Skip to content

Commit cda7ecf

Browse files
bors[bot]idanmuze
andauthored
Merge #977
977: added Third-Person-Shooter example r=chitoyuu a=idanmuze This PR is a port of the character controller from the official Godot TPS demo. The project currently utilizes a modified GDScript `_physics_process` function, unlike the Rust present for most of the project. The decision was a temporary fix to a very subtle character movement/rotation bug that I could not figure out. The somewhat working, intended Rust implementation is in the src folder under the name `_physics_process_wip`. I urge anyone with a solution or an explanation to let me know/open a PR so we can replace the GDScript ASAP. Co-authored-by: Jason Agbebaku <idanmuze@gmail.com>
2 parents 65018a8 + edcf593 commit cda7ecf

28 files changed

+2282
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
"examples/rpc",
1919
"examples/builder-export",
2020
"examples/property-export",
21+
"examples/godot_tps_controller_port",
2122
"impl/proc-macros"
2223
]
2324

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Player assets are acquired manually
2+
/player
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "tps_controller_port"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["The godot-rust developers"]
6+
publish = false
7+
rust-version = "1.63"
8+
license = "MIT"
9+
10+
[dependencies]
11+
gdnative = { path = "../../gdnative" , features = ["formatted"] }
12+
13+
[lib]
14+
crate-type = ["cdylib"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[gd_resource type="Environment" load_steps=2 format=2]
2+
3+
[sub_resource type="ProceduralSky" id=5]
4+
sky_top_color = Color( 0.568627, 0.698039, 0.807843, 1 )
5+
sky_horizon_color = Color( 0.67451, 0.705882, 0.733333, 1 )
6+
ground_bottom_color = Color( 0.121569, 0.121569, 0.129412, 1 )
7+
ground_horizon_color = Color( 0.67451, 0.705882, 0.733333, 1 )
8+
sun_latitude = 60.0
9+
sun_longitude = 30.0
10+
11+
[resource]
12+
background_mode = 2
13+
background_sky = SubResource( 5 )
14+
tonemap_mode = 2
15+
ssao_quality = 0
16+
ssao_blur = 2
17+
glow_enabled = true
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Levels/Main/Materials/M_Dark.tres" type="Material" id=1]
4+
5+
[sub_resource type="CubeMesh" id=1]
6+
7+
[sub_resource type="BoxShape" id=2]
8+
9+
[node name="Cube" type="MeshInstance"]
10+
mesh = SubResource( 1 )
11+
material/0 = ExtResource( 1 )
12+
13+
[node name="StaticBody" type="StaticBody" parent="."]
14+
15+
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
16+
shape = SubResource( 2 )
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Levels/Main/Materials/M_Dark.tres" type="Material" id=1]
4+
5+
[sub_resource type="CubeMesh" id=1]
6+
material = ExtResource( 1 )
7+
size = Vector3( 40, 0.5, 40 )
8+
9+
[sub_resource type="BoxShape" id=3]
10+
extents = Vector3( 20, 0.25, 20 )
11+
12+
[node name="Floor" type="MeshInstance"]
13+
mesh = SubResource( 1 )
14+
material/0 = null
15+
16+
[node name="StaticBody" type="StaticBody" parent="."]
17+
18+
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
19+
shape = SubResource( 3 )
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Levels/Main/Materials/M_Dark.tres" type="Material" id=1]
4+
5+
[sub_resource type="CubeMesh" id=2]
6+
material = ExtResource( 1 )
7+
size = Vector3( 40, 12, 1 )
8+
9+
[sub_resource type="BoxShape" id=4]
10+
extents = Vector3( 20, 6, 0.5 )
11+
12+
[node name="Wall" type="MeshInstance"]
13+
mesh = SubResource( 2 )
14+
material/0 = null
15+
16+
[node name="StaticBody" type="StaticBody" parent="."]
17+
18+
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
19+
shape = SubResource( 4 )
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
extends Spatial
2+
3+
#-----------------SCENE--SCRIPT------------------#
4+
# Close your game faster by clicking 'Esc' #
5+
# Change mouse mode by clicking 'Shift + F1' #
6+
#------------------------------------------------#
7+
8+
export var fast_close := true
9+
10+
11+
# Called when the node enters the scene tree for the first time.
12+
func _ready() -> void:
13+
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
14+
15+
if !OS.is_debug_build():
16+
fast_close = false
17+
18+
if fast_close:
19+
print("** Fast Close enabled in the 'L_Main.gd' script **")
20+
print("** 'Esc' to close 'Shift + F1' to release mouse **")
21+
22+
set_process_input(fast_close)
23+
24+
25+
func _input(event: InputEvent) -> void:
26+
if event.is_action_pressed("ui_cancel"):
27+
get_tree().quit() # Quits the game
28+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[gd_scene load_steps=7 format=2]
2+
3+
[ext_resource path="res://player/player.tscn" type="PackedScene" id=1]
4+
[ext_resource path="res://Levels/Main/Geometry/Floor.tscn" type="PackedScene" id=2]
5+
[ext_resource path="res://Levels/Main/Environment.tres" type="Environment" id=3]
6+
[ext_resource path="res://Levels/Main/L_Main.gd" type="Script" id=4]
7+
[ext_resource path="res://Levels/Main/Geometry/Wall.tscn" type="PackedScene" id=5]
8+
[ext_resource path="res://Levels/Main/Geometry/Cube.tscn" type="PackedScene" id=6]
9+
10+
[node name="L_Main" type="Spatial"]
11+
script = ExtResource( 4 )
12+
13+
[node name="ArenaGeometry" type="Spatial" parent="."]
14+
15+
[node name="Floor1" parent="ArenaGeometry" instance=ExtResource( 2 )]
16+
17+
[node name="Wall1" parent="ArenaGeometry" instance=ExtResource( 5 )]
18+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.75, -20 )
19+
20+
[node name="Wall2" parent="ArenaGeometry" instance=ExtResource( 5 )]
21+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.75, 20 )
22+
23+
[node name="Wall3" parent="ArenaGeometry" instance=ExtResource( 5 )]
24+
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 20, 5.75, 0 )
25+
26+
[node name="Wall4" parent="ArenaGeometry" instance=ExtResource( 5 )]
27+
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -20, 5.75, 0 )
28+
29+
[node name="Cube1" parent="ArenaGeometry" instance=ExtResource( 6 )]
30+
transform = Transform( 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2.25, -17.5 )
31+
32+
[node name="Slope1" parent="ArenaGeometry" instance=ExtResource( 6 )]
33+
transform = Transform( 3.5, 0, 0, 0, 1.53209, -2.41045, 0, 1.28558, 2.87267, 0, 0.31, -13.92 )
34+
35+
[node name="Platform1" parent="ArenaGeometry" instance=ExtResource( 6 )]
36+
transform = Transform( 6.25, 0, 0, 0, 0.25, 0, 0, 0, 2, -13.25, 5.75, -17.5 )
37+
38+
[node name="Platform2" parent="ArenaGeometry" instance=ExtResource( 6 )]
39+
transform = Transform( 6.25, 0, 0, 0, 0.25, 0, 0, 0, 2, 13.25, 5.75, -17.5 )
40+
41+
[node name="Platform3" parent="ArenaGeometry" instance=ExtResource( 6 )]
42+
transform = Transform( -2.73196e-07, 0, 2, 0, 0.25, 0, -6.25, 0, -8.74228e-08, -17.5, 5.75, -1.75 )
43+
44+
[node name="Platform4" parent="ArenaGeometry" instance=ExtResource( 6 )]
45+
transform = Transform( -2.73196e-07, 0, 2, 0, 0.25, 0, -6.25, 0, -8.74228e-08, 17.5, 5.75, -1.75 )
46+
47+
[node name="SlopeEnd1" parent="ArenaGeometry" instance=ExtResource( 6 )]
48+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 18, 3.5, 17.5 )
49+
50+
[node name="SlopeEnd2" parent="ArenaGeometry" instance=ExtResource( 6 )]
51+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -18, 3.5, 17.5 )
52+
53+
[node name="Slope2" parent="ArenaGeometry" instance=ExtResource( 6 )]
54+
transform = Transform( -3.2476, -0.125, -1.74846e-07, -1.875, 0.216506, 0, 2.83914e-07, 1.09278e-08, -2, 12.87, 1.66, 17.5 )
55+
56+
[node name="Slope3" parent="ArenaGeometry" instance=ExtResource( 6 )]
57+
transform = Transform( 3.2476, 0.125, 0, -1.875, 0.216506, 0, 0, 0, 2, -12.87, 1.66, 17.5 )
58+
59+
[node name="Platform5" parent="ArenaGeometry" instance=ExtResource( 6 )]
60+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 18, 3.5, 13.5 )
61+
62+
[node name="Platform6" parent="ArenaGeometry" instance=ExtResource( 6 )]
63+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 14, 3.5, 13.5 )
64+
65+
[node name="Platform7" parent="ArenaGeometry" instance=ExtResource( 6 )]
66+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 10, 3.5, 13.5 )
67+
68+
[node name="Platform8" parent="ArenaGeometry" instance=ExtResource( 6 )]
69+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 6, 3.5, 13.5 )
70+
71+
[node name="Platform9" parent="ArenaGeometry" instance=ExtResource( 6 )]
72+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 2, 3.5, 13.5 )
73+
74+
[node name="Platform10" parent="ArenaGeometry" instance=ExtResource( 6 )]
75+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -2, 3.5, 13.5 )
76+
77+
[node name="Platform11" parent="ArenaGeometry" instance=ExtResource( 6 )]
78+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -6, 3.5, 13.5 )
79+
80+
[node name="Platform12" parent="ArenaGeometry" instance=ExtResource( 6 )]
81+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -10, 3.5, 13.5 )
82+
83+
[node name="Platform13" parent="ArenaGeometry" instance=ExtResource( 6 )]
84+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -14, 3.5, 13.5 )
85+
86+
[node name="Platform14" parent="ArenaGeometry" instance=ExtResource( 6 )]
87+
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -18, 3.5, 13.5 )
88+
89+
[node name="TooSteep1" parent="ArenaGeometry" instance=ExtResource( 6 )]
90+
transform = Transform( -3.5, -0.216506, -3.01992e-07, -6.06218, 0.125, -1.51421e-07, 9.87455e-07, 2.32278e-08, -2, 16.5, 5.5, 8.5 )
91+
92+
[node name="TooSteep2" parent="ArenaGeometry" instance=ExtResource( 6 )]
93+
transform = Transform( 3.5, 0.216506, 0, -6.06218, 0.125, 0, 0, 0, 2, -16.5, 5.5, 8.5 )
94+
95+
[node name="Lighting" type="Node" parent="."]
96+
97+
[node name="WorldEnvironment" type="WorldEnvironment" parent="Lighting"]
98+
environment = ExtResource( 3 )
99+
100+
[node name="DirectionalLight" type="DirectionalLight" parent="Lighting"]
101+
transform = Transform( -0.866026, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 5, 0 )
102+
shadow_enabled = true
103+
shadow_bias = 0.05
104+
directional_shadow_max_distance = 250.0
105+
106+
[node name="Player" parent="." instance=ExtResource( 1 )]
107+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )

0 commit comments

Comments
 (0)