diff --git a/playtest-godot/Player.gd b/playtest-godot/Player.gd new file mode 100644 index 0000000..c72a31a --- /dev/null +++ b/playtest-godot/Player.gd @@ -0,0 +1,44 @@ +extends CharacterBody3D + + +const SPEED = 5.0 +const JUMP_VELOCITY = 4.5 + +# Get the gravity from the project settings to be synced with RigidDynamicBody nodes. +var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity") +@onready var neck := $Neck +@onready var camera := $Neck/Camera3D + +func _unhandled_input(event: InputEvent) -> void: + if event is InputEventMouseButton: + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + elif event.is_action_pressed("ui_cancel"): + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + if event is InputEventMouseMotion: + neck.rotate_y(-event.relative.x * 0.01) + camera.rotate_x(-event.relative.y * 0.01) + camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-30), deg_to_rad(60)) + + +func _physics_process(delta: float) -> void: + # Add the gravity. + if not is_on_floor(): + velocity.y -= gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var input_dir := Input.get_vector("left", "right", "forward", "back") + var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + if direction: + velocity.x = direction.x * SPEED + velocity.z = direction.z * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + velocity.z = move_toward(velocity.z, 0, SPEED) + + move_and_slide() diff --git a/playtest-godot/Player2.gd b/playtest-godot/Player2.gd new file mode 100644 index 0000000..e69de29 diff --git a/playtest-godot/Playtest.csproj b/playtest-godot/Playtest.csproj new file mode 100644 index 0000000..5e446e0 --- /dev/null +++ b/playtest-godot/Playtest.csproj @@ -0,0 +1,6 @@ + + + net6.0 + true + + \ No newline at end of file diff --git a/playtest-godot/Playtest.sln b/playtest-godot/Playtest.sln new file mode 100644 index 0000000..25128c4 --- /dev/null +++ b/playtest-godot/Playtest.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playtest", "Playtest.csproj", "{315CD57D-FAC2-4D4A-99E0-D9E812F081DC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {315CD57D-FAC2-4D4A-99E0-D9E812F081DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {315CD57D-FAC2-4D4A-99E0-D9E812F081DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {315CD57D-FAC2-4D4A-99E0-D9E812F081DC}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {315CD57D-FAC2-4D4A-99E0-D9E812F081DC}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {315CD57D-FAC2-4D4A-99E0-D9E812F081DC}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {315CD57D-FAC2-4D4A-99E0-D9E812F081DC}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/playtest-godot/node_3d.cs b/playtest-godot/node_3d.cs new file mode 100644 index 0000000..3e5658f --- /dev/null +++ b/playtest-godot/node_3d.cs @@ -0,0 +1,15 @@ +using Godot; +using System; + +public partial class node_3d : Node3D +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } +} diff --git a/playtest-godot/node_3d.tscn b/playtest-godot/node_3d.tscn index ca08cbc..ddf8d83 100644 --- a/playtest-godot/node_3d.tscn +++ b/playtest-godot/node_3d.tscn @@ -1,30 +1,76 @@ -[gd_scene load_steps=3 format=3 uid="uid://fteqjds0ur7d"] +[gd_scene load_steps=6 format=3 uid="uid://fteqjds0ur7d"] -[sub_resource type="CapsuleMesh" id="CapsuleMesh_jby51"] +[ext_resource type="Script" path="res://Player.gd" id="1_iygeh"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_d63w3"] -[node name="Node3D" type="Node3D"] +[sub_resource type="CapsuleMesh" id="CapsuleMesh_jby51"] -[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_tb0e8"] + +[sub_resource type="CapsuleMesh" id="CapsuleMesh_kjbnh"] + +[node name="Shit" type="Node3D"] + +[node name="Building" type="Node3D" parent="."] + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Building"] transform = Transform3D(-0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 0, 0) light_color = Color(0.898039, 0.717647, 1, 1) shadow_enabled = true -[node name="CSGBox3D" type="CSGBox3D" parent="."] +[node name="CSGBox3D5" type="CSGBox3D" parent="Building"] +transform = Transform3D(-2.17762e-07, 0, -2.49798, 0, 1.44485, 0, 4.98181, 0, -1.0919e-07, 6.56848, 7.02783, 16.8147) +use_collision = true +size = Vector3(1, 2.14659, 15.4055) + +[node name="CSGBox3D4" type="CSGBox3D" parent="Building"] +transform = Transform3D(4.98181, 0, 0, 0, 1.44485, 0, 0, 0, 2.49798, -9.86052, 7.17377, 2.77689) +use_collision = true +size = Vector3(1, 2.14659, 11.0479) + +[node name="CSGBox3D" type="CSGBox3D" parent="Building"] transform = Transform3D(8.58594, 0, 0, 0, 2.00279, 0, 0, 0, 6.86688, 4.35189, 5.74543, 4.01569) +use_collision = true size = Vector3(2.71647, 1, 3.46432) -[node name="CharacterBody3D" type="CharacterBody3D" parent="."] +[node name="CSGBox3D3" type="CSGBox3D" parent="Building"] +transform = Transform3D(-2.17762e-07, 0, -2.49798, 0, 1.44485, 0, 4.98181, 0, -1.0919e-07, 4.61739, 8.21841, -10.4649) +use_collision = true +size = Vector3(1, 2.14659, 9.46679) + +[node name="CSGBox3D2" type="CSGBox3D" parent="Building"] +transform = Transform3D(2.232, 0, 0, 0, 1.20202, 0, 0, 0, 1.5805, 17.2131, 8.01648, 3.68603) +use_collision = true +size = Vector3(1, 2.14659, 15.4055) + +[node name="Player" type="CharacterBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.07412, 7.81608, -2.32601) +script = ExtResource("1_iygeh") -[node name="MeshInstance3D" type="MeshInstance3D" parent="CharacterBody3D"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.242787, -0.274989, 0.518757) -mesh = SubResource("CapsuleMesh_jby51") - -[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.243412, -0.280069, 0.514035) shape = SubResource("CapsuleShape3D_d63w3") -[node name="Camera3D" type="Camera3D" parent="CharacterBody3D"] +[node name="Neck" type="Node3D" parent="Player"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Player/Neck"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.242787, -0.274989, 0.518757) +mesh = SubResource("CapsuleMesh_jby51") +skeleton = NodePath("../..") + +[node name="Camera3D" type="Camera3D" parent="Player/Neck"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.245579, 0.273289, -0.0169597) + +[node name="Player2Test" type="Node3D" parent="."] + +[node name="CharacterBody3D" type="CharacterBody3D" parent="Player2Test"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Player2Test/CharacterBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.97565, 0) +shape = SubResource("CapsuleShape3D_tb0e8") +disabled = true + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Player2Test/CharacterBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8.01226, 0) +mesh = SubResource("CapsuleMesh_kjbnh") diff --git a/playtest-godot/project.godot b/playtest-godot/project.godot index df0c0d1..4dd60de 100644 --- a/playtest-godot/project.godot +++ b/playtest-godot/project.godot @@ -12,5 +12,32 @@ config_version=5 config/name="Playtest" run/main_scene="res://node_3d.tscn" -config/features=PackedStringArray("4.0", "Forward Plus") +config/features=PackedStringArray("4.0", "C#", "Forward Plus") config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="Playtest" + +[input] + +forward={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +] +} +back={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +] +} +left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +] +} +right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +] +}