Merge pull request 'Add player movement' (#13) from features/jant/2-player-movement into main

Reviewed-on: #13
This commit is contained in:
Aslan 2026-01-24 18:39:55 +01:00
commit 228e0c43b0
27 changed files with 631 additions and 1 deletions

4
.editorconfig Normal file
View file

@ -0,0 +1,4 @@
root = true
[*]
charset = utf-8

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
# ---> Godot # ---> Godot
# Godot 4+ specific ignores # Godot 4+ specific ignores
.godot/ .godot/
/android/
# Godot-specific ignores # Godot-specific ignores
.import/ .import/

11
Imperfect Space.csproj Normal file
View file

@ -0,0 +1,11 @@
<Project Sdk="Godot.NET.Sdk/4.6.0-rc.2">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework
Condition=" '$(GodotTargetPlatform)' == 'android' "
>net9.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>ImperfectSpace</RootNamespace>
<SuppressImplicitGitSourceLink>true</SuppressImplicitGitSourceLink>
</PropertyGroup>
</Project>

19
Imperfect Space.sln Normal file
View file

@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Imperfect Space", "Imperfect Space.csproj", "{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}"
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
{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
{93B3F7D2-13DE-425C-89B4-C80E0B48EAB7}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
EndGlobalSection
EndGlobal

View file

@ -1,3 +1,3 @@
# imperfect-space # imperfect-space
Space RPG Simulation Game Space RPG Simulation Game

1
icon.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>

After

Width:  |  Height:  |  Size: 995 B

43
icon.svg.import Normal file
View file

@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d1qrx53nygt1v"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

76
project.godot Normal file
View file

@ -0,0 +1,76 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Imperfect Space"
run/main_scene="uid://bnmh1mebldx4l"
config/features=PackedStringArray("4.6", "C#", "Forward Plus")
config/icon="res://icon.svg"
[dotnet]
project/assembly_name="Imperfect Space"
[input]
jump={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.2,
"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,"location":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.2,
"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,"location":0,"echo":false,"script":null)
]
}
move_forward={
"deadzone": 0.2,
"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,"location":0,"echo":false,"script":null)
]
}
move_back={
"deadzone": 0.2,
"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,"location":0,"echo":false,"script":null)
]
}
move_up={
"deadzone": 0.2,
"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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
move_down={
"deadzone": 0.2,
"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":4194326,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
rotate_left={
"deadzone": 0.2,
"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":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
]
}
rotate_right={
"deadzone": 0.2,
"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":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
]
}
[physics]
3d/physics_engine="Jolt Physics"
[rendering]
rendering_device/driver.windows="d3d12"

122
scenes/game.tscn Normal file
View file

@ -0,0 +1,122 @@
[gd_scene format=3 uid="uid://b3yh6h7fdt160"]
[ext_resource type="Script" uid="uid://cue3c56axvyja" path="res://scripts/Player.cs" id="1_uwrxv"]
[ext_resource type="Script" uid="uid://cy8nuarxbnd" path="res://scripts/GravityZone.cs" id="1_yqjtg"]
[ext_resource type="Script" uid="uid://bwpdtkgmwjs7g" path="res://scripts/GravityReceiver.cs" id="3_lnu2h"]
[ext_resource type="Script" uid="uid://n557xfrv0i6x" path="res://scripts/GeneralControlManager.cs" id="4_lbhrr"]
[ext_resource type="Script" uid="uid://betypbypf6bf2" path="res://scripts/GameMenuController.cs" id="5_iywne"]
[sub_resource type="PlaneMesh" id="PlaneMesh_8cj0n"]
[sub_resource type="BoxShape3D" id="BoxShape3D_8cj0n"]
size = Vector3(10, 0.5, 10)
[sub_resource type="BoxShape3D" id="BoxShape3D_uwrxv"]
size = Vector3(10, 5, 10)
[sub_resource type="CapsuleMesh" id="CapsuleMesh_8cj0n"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_uwrxv"]
[node name="Game" type="Node3D" unique_id=1201210338]
[node name="Plane2" type="StaticBody3D" parent="." unique_id=289682669]
transform = Transform3D(1, 0, 0, 0, 0.99999994, 0, 0, 0, 0.99999994, -20.320108, 0, 0)
[node name="PlaneMesh" type="MeshInstance3D" parent="Plane2" unique_id=1859317875]
transform = Transform3D(5, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0)
mesh = SubResource("PlaneMesh_8cj0n")
[node name="PlaneCollider" type="CollisionShape3D" parent="Plane2" unique_id=907638578]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, 0)
shape = SubResource("BoxShape3D_8cj0n")
[node name="GravityZone" type="Area3D" parent="Plane2" unique_id=600317513]
gravity_space_override = 2
script = ExtResource("1_yqjtg")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Plane2/GravityZone" unique_id=991265750]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.5, 0)
shape = SubResource("BoxShape3D_uwrxv")
[node name="Plane" type="StaticBody3D" parent="." unique_id=1260154250]
transform = Transform3D(1, 0, 0, 0, 0.70710677, 0.70710677, 0, -0.70710677, 0.70710677, 0, 0, 0)
[node name="PlaneMesh" type="MeshInstance3D" parent="Plane" unique_id=107049489]
transform = Transform3D(5, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0)
mesh = SubResource("PlaneMesh_8cj0n")
[node name="PlaneCollider" type="CollisionShape3D" parent="Plane" unique_id=970373853]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, 0)
shape = SubResource("BoxShape3D_8cj0n")
[node name="GravityZone" type="Area3D" parent="Plane" unique_id=1326543003]
gravity_space_override = 2
script = ExtResource("1_yqjtg")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Plane/GravityZone" unique_id=772916098]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.5, 0)
shape = SubResource("BoxShape3D_uwrxv")
[node name="Player" type="CharacterBody3D" parent="." unique_id=612572257 node_paths=PackedStringArray("GameMenu")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.1320534, 0.7854848)
script = ExtResource("1_uwrxv")
GameMenu = NodePath("../GameMenu")
[node name="Camera" type="Camera3D" parent="Player" unique_id=1097983892]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)
fov = 90.0
[node name="PlayerMesh" type="MeshInstance3D" parent="Player" unique_id=1440613415]
mesh = SubResource("CapsuleMesh_8cj0n")
[node name="PlayerCollider" type="CollisionShape3D" parent="Player" unique_id=886478863]
shape = SubResource("CapsuleShape3D_uwrxv")
[node name="GravityReceiver" type="Node3D" parent="Player" unique_id=1963556576]
script = ExtResource("3_lnu2h")
[node name="OmniLight" type="OmniLight3D" parent="." unique_id=1887866205]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6497431, -4.41529)
omni_range = 95.383
omni_attenuation = 0.254
[node name="GeneralControlManager" type="Node" parent="." unique_id=1751385863 node_paths=PackedStringArray("GameMenu")]
script = ExtResource("4_lbhrr")
GameMenu = NodePath("../GameMenu")
[node name="GameMenu" type="Control" parent="." unique_id=223510406]
visible = false
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("5_iywne")
[node name="Overlay" type="ColorRect" parent="GameMenu" unique_id=255916820]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.2509804)
[node name="VBoxContainer" type="VBoxContainer" parent="GameMenu" unique_id=502136213]
layout_mode = 0
offset_left = 32.0
offset_top = 32.0
offset_right = 128.0
offset_bottom = 63.0
[node name="MainMenuButton" type="Button" parent="GameMenu/VBoxContainer" unique_id=1125420773]
layout_mode = 2
text = "Main Menu"
[connection signal="body_entered" from="Plane2/GravityZone" to="Plane2/GravityZone" method="OnBodyEntered"]
[connection signal="body_exited" from="Plane2/GravityZone" to="Plane2/GravityZone" method="OnBodyExited"]
[connection signal="body_entered" from="Plane/GravityZone" to="Plane/GravityZone" method="OnBodyEntered"]
[connection signal="body_exited" from="Plane/GravityZone" to="Plane/GravityZone" method="OnBodyExited"]
[connection signal="pressed" from="GameMenu/VBoxContainer/MainMenuButton" to="GameMenu" method="OnMainMenu"]

35
scenes/main_menu.tscn Normal file
View file

@ -0,0 +1,35 @@
[gd_scene format=3 uid="uid://bnmh1mebldx4l"]
[ext_resource type="Script" uid="uid://b7inoxterktk3" path="res://scripts/MainMenu/MainMenuController.cs" id="1_l6cm7"]
[node name="MainMenu" type="Control" unique_id=1620629749]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_l6cm7")
[node name="CenterContainer" type="CenterContainer" parent="." unique_id=601944177]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer" unique_id=180209254]
layout_mode = 2
alignment = 1
[node name="StartGameButton" type="Button" parent="CenterContainer/VBoxContainer" unique_id=364461644]
layout_mode = 2
text = "Start Game"
[node name="ExitGameButton" type="Button" parent="CenterContainer/VBoxContainer" unique_id=1050417063]
layout_mode = 2
text = "Exit Game"
[connection signal="pressed" from="CenterContainer/VBoxContainer/StartGameButton" to="." method="OnStartGame"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/ExitGameButton" to="." method="OnExitGame"]

3
scripts/Constants.cs Normal file
View file

@ -0,0 +1,3 @@
public static partial class Constants
{
}

1
scripts/Constants.cs.uid Normal file
View file

@ -0,0 +1 @@
uid://dxtvl7k4e3nn4

View file

@ -0,0 +1,9 @@
using Godot;
public partial class GameMenuController : Control
{
public void OnMainMenu()
{
GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
}
}

View file

@ -0,0 +1 @@
uid://betypbypf6bf2

View file

@ -0,0 +1,41 @@
using Godot;
public partial class GeneralControlManager : Node
{
[Export] Control GameMenu;
public override void _Ready()
{
Input.MouseMode = Input.MouseModeEnum.Captured;
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("ui_cancel"))
{
if (GameMenu.Visible)
{
HideMenu();
}
else
{
ShowMenu();
}
return;
}
}
public void ShowMenu()
{
GameMenu.Show();
Input.MouseMode = Input.MouseModeEnum.Visible;
}
public void HideMenu()
{
GameMenu.Hide();
Input.MouseMode = Input.MouseModeEnum.Captured;
}
}

View file

@ -0,0 +1 @@
uid://n557xfrv0i6x

View file

@ -0,0 +1,22 @@
using Godot;
public partial class GravityReceiver : Node3D
{
public bool InGravityZone = false;
public float GravityStrength = 0f;
public Vector3 GravityDirection = Vector3.Down;
public void EnterGravityZone(float gravityStrength, Vector3 gravityDirection)
{
InGravityZone = true;
GravityStrength = gravityStrength;
GravityDirection = gravityDirection;
}
public void ExitGravityZone()
{
InGravityZone = false;
GravityStrength = 0f;
GravityDirection = Vector3.Down;
}
}

View file

@ -0,0 +1 @@
uid://bwpdtkgmwjs7g

16
scripts/GravityZone.cs Normal file
View file

@ -0,0 +1,16 @@
using Godot;
public partial class GravityZone : Area3D
{
public void OnBodyEntered(Node3D body)
{
GravityReceiver receiver = body.GetNodeOrNull<GravityReceiver>("GravityReceiver");
receiver?.EnterGravityZone(Gravity, GlobalTransform.Basis.Y);
}
public void OnBodyExited(Node3D body)
{
GravityReceiver receiver = body.GetNodeOrNull<GravityReceiver>("GravityReceiver");
receiver?.ExitGravityZone();
}
}

View file

@ -0,0 +1 @@
uid://cy8nuarxbnd

3
scripts/Helpers.cs Normal file
View file

@ -0,0 +1,3 @@
public static partial class Helpers
{
}

1
scripts/Helpers.cs.uid Normal file
View file

@ -0,0 +1 @@
uid://de2nkadeybqn0

View file

@ -0,0 +1,14 @@
using Godot;
public partial class MainMenuController : Node
{
public void OnStartGame()
{
GetTree().ChangeSceneToFile("res://scenes/game.tscn");
}
public void OnExitGame()
{
GetTree().Quit();
}
}

View file

@ -0,0 +1 @@
uid://b7inoxterktk3

200
scripts/Player.cs Normal file
View file

@ -0,0 +1,200 @@
using Godot;
public partial class Player : CharacterBody3D
{
[Export] Control GameMenu;
[Export] public float Speed = 5f;
[Export] public float JumpForce = 5f;
[Export] public float MouseSensitivity = 0.2f;
private Vector3 gravityVelocity = Vector3.Zero;
private Vector3 movementVelocity = Vector3.Zero;
private float cameraPitch = 0f;
private Camera3D camera;
private GravityReceiver gravityReceiver;
public override void _Ready()
{
camera = GetNode<Camera3D>("Camera");
gravityReceiver = GetNode<GravityReceiver>("GravityReceiver");
}
public override void _PhysicsProcess(double delta)
{
Vector3 newGravityVelocity = gravityVelocity;
Vector3 newMovementVelocity = movementVelocity;
if (IsInGravity())
{
ProcessGravity(delta, ref newGravityVelocity);
if (!GameMenu.Visible)
{
ProcessControlsGravity(ref newGravityVelocity, ref newMovementVelocity);
}
}
else
{
newGravityVelocity = Vector3.Zero;
ProcessCamera(delta);
if (!GameMenu.Visible)
{
ProcessControls(ref newMovementVelocity);
}
}
gravityVelocity = newGravityVelocity;
movementVelocity = newMovementVelocity;
Velocity = newGravityVelocity + newMovementVelocity;
MoveAndSlide();
}
public override void _Input(InputEvent @event)
{
if (GameMenu.Visible)
{
return;
}
if (@event is InputEventMouseMotion motion)
{
float yawDelta = -motion.Relative.X * MouseSensitivity;
float yawDeltaRad = Mathf.DegToRad(yawDelta);
float pitchDelta = -motion.Relative.Y * MouseSensitivity;
float pitchDeltaRad = Mathf.DegToRad(pitchDelta);
RotateObjectLocal(Vector3.Up, yawDeltaRad);
if (IsInGravity())
{
cameraPitch = Mathf.Clamp(cameraPitch + pitchDelta, -90f, 90f);
}
else
{
RotateObjectLocal(Vector3.Right, pitchDeltaRad);
}
camera.RotationDegrees = new Vector3(cameraPitch, 0, 0);
}
}
public bool IsInGravity()
{
return gravityReceiver.InGravityZone && gravityReceiver.GravityStrength > 0f;
}
public bool IsOnGravityFloor()
{
for (int i = 0; i < GetSlideCollisionCount(); i++)
{
KinematicCollision3D collision = GetSlideCollision(i);
Vector3 collisionNormal = collision.GetNormal();
float alignment = collisionNormal.Dot(gravityReceiver.GravityDirection);
if (alignment > 0.7f)
{
return true;
}
}
return false;
}
private void ProcessGravity(double delta, ref Vector3 newGravityVelocity)
{
if (!IsOnGravityFloor())
{
newGravityVelocity -= gravityReceiver.GravityDirection * gravityReceiver.GravityStrength * (float)delta;
}
else
{
newGravityVelocity = -gravityReceiver.GravityDirection;
}
Vector3 currentUp = GlobalTransform.Basis.Y;
Vector3 targetUp = gravityReceiver.GravityDirection;
Vector3 axis = currentUp.Cross(targetUp);
if (axis.Length() < 0.00001f)
{
return;
}
float angle = currentUp.AngleTo(targetUp);
Rotate(axis.Normalized(), angle * (float)delta * 10f);
}
private void ProcessCamera(double delta)
{
if (cameraPitch > 0.01f)
{
cameraPitch -= 90f * (float)delta;
}
else if (cameraPitch < -0.001f)
{
cameraPitch += 90f * (float)delta;
}
if (Mathf.Abs(cameraPitch) < 1f)
{
cameraPitch = 0f;
}
camera.RotationDegrees = new Vector3(cameraPitch, 0, 0);
}
private void ProcessControlsGravity(ref Vector3 newGravityVelocity, ref Vector3 newMovementVelocity)
{
float inputX = Input.GetAxis("move_left", "move_right");
float inputZ = Input.GetAxis("move_forward", "move_back");
Vector3 direction = Transform.Basis.X * inputX + Transform.Basis.Z * inputZ;
if (direction != Vector3.Zero)
{
newMovementVelocity.X = direction.X * Speed;
newMovementVelocity.Y = direction.Y * Speed;
newMovementVelocity.Z = direction.Z * Speed;
}
else
{
newMovementVelocity.X = 0f;
newMovementVelocity.Y = 0f;
newMovementVelocity.Z = 0f;
}
if (Input.IsActionJustPressed("jump") && IsOnGravityFloor())
{
newGravityVelocity = gravityReceiver.GravityDirection * JumpForce;
}
}
private void ProcessControls(ref Vector3 newMovementVelocity)
{
float inputX = Input.GetAxis("move_left", "move_right");
float inputY = -Input.GetAxis("move_up", "move_down");
float inputZ = Input.GetAxis("move_forward", "move_back");
Vector3 direction = Transform.Basis.X * inputX + Transform.Basis.Y * inputY + Transform.Basis.Z * inputZ;
if (direction != Vector3.Zero)
{
newMovementVelocity.X = direction.X * Speed;
newMovementVelocity.Y = direction.Y * Speed;
newMovementVelocity.Z = direction.Z * Speed;
}
else
{
newMovementVelocity.X = 0f;
newMovementVelocity.Y = 0f;
newMovementVelocity.Z = 0f;
}
float inputRotateZ = Input.GetAxis("rotate_left", "rotate_right");
float rotateAmountZ = Mathf.DegToRad(inputRotateZ);
RotateObjectLocal(Vector3.Forward, rotateAmountZ);
}
}

1
scripts/Player.cs.uid Normal file
View file

@ -0,0 +1 @@
uid://cue3c56axvyja