Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Third-Person-Shooter example #977

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"examples/rpc",
"examples/builder-export",
"examples/property-export",
"examples/godot_tps_controller_port",
"impl/proc-macros"
]

Expand Down
2 changes: 2 additions & 0 deletions examples/godot_tps_controller_port/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Player assets are acquired manually
/player
14 changes: 14 additions & 0 deletions examples/godot_tps_controller_port/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "tps_controller_port"
version = "0.1.0"
edition = "2021"
authors = ["The godot-rust developers"]
publish = false
rust-version = "1.63"
license = "MIT"

[dependencies]
gdnative = { path = "../../gdnative" , features = ["formatted"] }

[lib]
crate-type = ["cdylib"]
19 changes: 19 additions & 0 deletions examples/godot_tps_controller_port/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions examples/godot_tps_controller_port/Levels/Main/Environment.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[gd_resource type="Environment" load_steps=2 format=2]

[sub_resource type="ProceduralSky" id=5]
sky_top_color = Color( 0.568627, 0.698039, 0.807843, 1 )
sky_horizon_color = Color( 0.67451, 0.705882, 0.733333, 1 )
ground_bottom_color = Color( 0.121569, 0.121569, 0.129412, 1 )
ground_horizon_color = Color( 0.67451, 0.705882, 0.733333, 1 )
sun_latitude = 60.0
sun_longitude = 30.0

[resource]
background_mode = 2
background_sky = SubResource( 5 )
tonemap_mode = 2
ssao_quality = 0
ssao_blur = 2
glow_enabled = true
16 changes: 16 additions & 0 deletions examples/godot_tps_controller_port/Levels/Main/Geometry/Cube.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Levels/Main/Materials/M_Dark.tres" type="Material" id=1]

[sub_resource type="CubeMesh" id=1]

[sub_resource type="BoxShape" id=2]

[node name="Cube" type="MeshInstance"]
mesh = SubResource( 1 )
material/0 = ExtResource( 1 )

[node name="StaticBody" type="StaticBody" parent="."]

[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
shape = SubResource( 2 )
19 changes: 19 additions & 0 deletions examples/godot_tps_controller_port/Levels/Main/Geometry/Floor.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Levels/Main/Materials/M_Dark.tres" type="Material" id=1]

[sub_resource type="CubeMesh" id=1]
material = ExtResource( 1 )
size = Vector3( 40, 0.5, 40 )

[sub_resource type="BoxShape" id=3]
extents = Vector3( 20, 0.25, 20 )

[node name="Floor" type="MeshInstance"]
mesh = SubResource( 1 )
material/0 = null

[node name="StaticBody" type="StaticBody" parent="."]

[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
shape = SubResource( 3 )
19 changes: 19 additions & 0 deletions examples/godot_tps_controller_port/Levels/Main/Geometry/Wall.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Levels/Main/Materials/M_Dark.tres" type="Material" id=1]

[sub_resource type="CubeMesh" id=2]
material = ExtResource( 1 )
size = Vector3( 40, 12, 1 )

[sub_resource type="BoxShape" id=4]
extents = Vector3( 20, 6, 0.5 )

[node name="Wall" type="MeshInstance"]
mesh = SubResource( 2 )
material/0 = null

[node name="StaticBody" type="StaticBody" parent="."]

[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
shape = SubResource( 4 )
28 changes: 28 additions & 0 deletions examples/godot_tps_controller_port/Levels/Main/L_Main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends Spatial

#-----------------SCENE--SCRIPT------------------#
# Close your game faster by clicking 'Esc' #
# Change mouse mode by clicking 'Shift + F1' #
#------------------------------------------------#

export var fast_close := true


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

if !OS.is_debug_build():
fast_close = false

if fast_close:
print("** Fast Close enabled in the 'L_Main.gd' script **")
print("** 'Esc' to close 'Shift + F1' to release mouse **")

set_process_input(fast_close)


func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel"):
get_tree().quit() # Quits the game

107 changes: 107 additions & 0 deletions examples/godot_tps_controller_port/Levels/Main/L_Main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[gd_scene load_steps=7 format=2]

[ext_resource path="res://player/player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Levels/Main/Geometry/Floor.tscn" type="PackedScene" id=2]
[ext_resource path="res://Levels/Main/Environment.tres" type="Environment" id=3]
[ext_resource path="res://Levels/Main/L_Main.gd" type="Script" id=4]
[ext_resource path="res://Levels/Main/Geometry/Wall.tscn" type="PackedScene" id=5]
[ext_resource path="res://Levels/Main/Geometry/Cube.tscn" type="PackedScene" id=6]

[node name="L_Main" type="Spatial"]
script = ExtResource( 4 )

[node name="ArenaGeometry" type="Spatial" parent="."]

[node name="Floor1" parent="ArenaGeometry" instance=ExtResource( 2 )]

[node name="Wall1" parent="ArenaGeometry" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.75, -20 )

[node name="Wall2" parent="ArenaGeometry" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.75, 20 )

[node name="Wall3" parent="ArenaGeometry" instance=ExtResource( 5 )]
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 20, 5.75, 0 )

[node name="Wall4" parent="ArenaGeometry" instance=ExtResource( 5 )]
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -20, 5.75, 0 )

[node name="Cube1" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2.25, -17.5 )

[node name="Slope1" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 3.5, 0, 0, 0, 1.53209, -2.41045, 0, 1.28558, 2.87267, 0, 0.31, -13.92 )

[node name="Platform1" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 6.25, 0, 0, 0, 0.25, 0, 0, 0, 2, -13.25, 5.75, -17.5 )

[node name="Platform2" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 6.25, 0, 0, 0, 0.25, 0, 0, 0, 2, 13.25, 5.75, -17.5 )

[node name="Platform3" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( -2.73196e-07, 0, 2, 0, 0.25, 0, -6.25, 0, -8.74228e-08, -17.5, 5.75, -1.75 )

[node name="Platform4" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( -2.73196e-07, 0, 2, 0, 0.25, 0, -6.25, 0, -8.74228e-08, 17.5, 5.75, -1.75 )

[node name="SlopeEnd1" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 18, 3.5, 17.5 )

[node name="SlopeEnd2" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -18, 3.5, 17.5 )

[node name="Slope2" parent="ArenaGeometry" instance=ExtResource( 6 )]
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 )

[node name="Slope3" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 3.2476, 0.125, 0, -1.875, 0.216506, 0, 0, 0, 2, -12.87, 1.66, 17.5 )

[node name="Platform5" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 18, 3.5, 13.5 )

[node name="Platform6" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 14, 3.5, 13.5 )

[node name="Platform7" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 10, 3.5, 13.5 )

[node name="Platform8" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 6, 3.5, 13.5 )

[node name="Platform9" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, 2, 3.5, 13.5 )

[node name="Platform10" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -2, 3.5, 13.5 )

[node name="Platform11" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -6, 3.5, 13.5 )

[node name="Platform12" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -10, 3.5, 13.5 )

[node name="Platform13" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -14, 3.5, 13.5 )

[node name="Platform14" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 2, 0, 0, 0, 0.25, 0, 0, 0, 2, -18, 3.5, 13.5 )

[node name="TooSteep1" parent="ArenaGeometry" instance=ExtResource( 6 )]
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 )

[node name="TooSteep2" parent="ArenaGeometry" instance=ExtResource( 6 )]
transform = Transform( 3.5, 0.216506, 0, -6.06218, 0.125, 0, 0, 0, 2, -16.5, 5.5, 8.5 )

[node name="Lighting" type="Node" parent="."]

[node name="WorldEnvironment" type="WorldEnvironment" parent="Lighting"]
environment = ExtResource( 3 )

[node name="DirectionalLight" type="DirectionalLight" parent="Lighting"]
transform = Transform( -0.866026, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 5, 0 )
shadow_enabled = true
shadow_bias = 0.05
directional_shadow_max_distance = 250.0

[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="SpatialMaterial" load_steps=2 format=2]

[ext_resource path="res://Levels/Main/Materials/T_Grid.png" type="Texture" id=1]

[resource]
params_diffuse_mode = 1
albedo_texture = ExtResource( 1 )
metallic_specular = 0.0
uv1_scale = Vector3( 0.5, 0.5, 0.5 )
uv1_offset = Vector3( 0.5, 0.5, 0.5 )
uv1_triplanar = true
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="StreamTexture"
path.s3tc="res://.import/T_Grid.png-e5c46bba002abd59c6e5c194a065636e.s3tc.stex"
path.etc2="res://.import/T_Grid.png-e5c46bba002abd59c6e5c194a065636e.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}

[deps]

source_file="res://Levels/Main/Materials/T_Grid.png"
dest_files=[ "res://.import/T_Grid.png-e5c46bba002abd59c6e5c194a065636e.s3tc.stex", "res://.import/T_Grid.png-e5c46bba002abd59c6e5c194a065636e.etc2.stex" ]

[params]

compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=false
flags/mipmaps=true
flags/anisotropic=true
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
9 changes: 9 additions & 0 deletions examples/godot_tps_controller_port/Player.gdns
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]

[ext_resource path="res://godot_rust_tps_port.gdnlib" type="GDNativeLibrary" id=1]

[resource]
resource_name = "Player"
class_name = "Player"
library = ExtResource( 1 )
script_class_name = "PlayerScript"
65 changes: 65 additions & 0 deletions examples/godot_tps_controller_port/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Godot Rust Third Person Example ![Godot 3.5](https://img.shields.io/badge/godot-v3.5-%23478cbf)

Rust port of the character controller from the official Godot Third-Person-Shooter demo.

### Important notes!:
- Due to file size, the player model asset is not included in the repository and therefore is unincluded with this example.
- To get it, follow the five-minute guide below.
- When opening Player.tcsn, the console may flood with the following error messages:

```
ERROR: Index p_point = 5 is out of bounds (blend_points_used = 5).
at: get_blend_point_node (scene/animation/animation_blend_space_2d.cpp:110)
ERROR: Index p_point = 6 is out of bounds (blend_points_used = 5).
at: get_blend_point_node (scene/animation/animation_blend_space_2d.cpp:110)
ERROR: Index p_point = 7 is out of bounds (blend_points_used = 5).
at: get_blend_point_node (scene/animation/animation_blend_space_2d.cpp:110)
...
```

- This also occurs in the original official project and can be safely ignored.

### Guide on bringing the player model asset into the Godot-Rust TPS example:

- _Ensure you complete steps 1-3 BEFORE opening the project to avoid dependency issues)._

- _You do NOT need to open the regular (GDScript scripted) TPS demo you download from GitHub. You are merely getting the player model folder from it and moving it to the Godot-Rust TPS example, as it is unincluded automatically._

#### Step 1:
- Go to the Godot official GitHub page and select the TPS demo
- Link here: https://github.com/godotengine/tps-demo

#### Step 2:
- Press the "Code" button and, in the resulting dropdown, press "Download Zip."

#### Step 3:
- Extract the downloaded zip folder and move the unzipped "player" folder into the Godot-Rust TPS example project folder.

#### Step 4:
- Open the project. The player character should have a GDScript script attached. Replace that with the Nativescript Player.gdns. You should be good to go to build the project!

- Godot will complain about missing dependencies if you open the project before completing steps 1-3. If you do this, complete steps 1-3 and then tell Godot where the files are in the popup.

### Includes:
- 3D Character Controller
- Smooth Movement
- Smooth Camera Rotation
- Aiming
- Root Motion and Animation Controls
- Example 3D Scene

### Project Controls:
- Move with `W` `A` `S` `D` , `↑` `←` `↓` `→` or controller input.
- Close Game with `Esc`
- Standard FPS controls for aiming and shooting: e.g. `Right Click` or `L2` for aiming

### Credits:
#### Grid Texture/s
- By [KenneyNL](https://www.kenney.nl/assets/prototype-textures)
- Licensed under the terms of the Creative Commons Public Domain Dedication License (CCO 1.0)
#### Level Template
- By [Whimfoome](https://github.com/Whimfoome/godot-FirstPersonStarter)
- Licensed under the terms of the MIT License
#### Player-Character Assets
- [Copyright (c) 2018 Juan Linietsky, Fernando Miguel Calabró](https://github.com/godotengine/tps-demo)
- Licensed under the terms of the Creative Commons Attribution License version 3.0 (CC-BY 3.0)
7 changes: 7 additions & 0 deletions examples/godot_tps_controller_port/default_env.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]

[sub_resource type="ProceduralSky" id=1]

[resource]
background_mode = 2
background_sky = SubResource( 1 )
Binary file not shown.
Loading