From 01f86cd78d80bab6581f3b173755681121edcf43 Mon Sep 17 00:00:00 2001 From: anyreso Date: Wed, 11 Dec 2024 18:52:03 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20player=20motion=20computat?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entities/player/player.gd | 23 +++++++++++------------ entities/player/player.tscn | 22 ---------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/entities/player/player.gd b/entities/player/player.gd index e6c1f12..2f51da8 100644 --- a/entities/player/player.gd +++ b/entities/player/player.gd @@ -277,19 +277,18 @@ func _integrate_forces(_state:PhysicsDirectBodyState3D) -> void: # retrieve collision normal var normal:Vector3 = walkable_surface_sensor.get_collision_normal(0) - if not view_direction.is_zero_approx() and not input.skiing: - # calculate the angle between the ground normal and the up vector - var slope_angle:float = rad_to_deg(acos(normal.dot(Vector3.UP))) - # check if the slope angle exceeds the maximum slope angle - if slope_angle <= max_floor_angle: - # adjust direction based on the floor normal to align with the slope - view_direction = view_direction.slide(normal) - - linear_velocity = lerp(linear_velocity, view_direction * ground_speed, .1) - + if not input.direction.is_zero_approx(): + if not input.skiing: + # calculate the angle between the ground normal and the up vector + var slope_angle:float = rad_to_deg(acos(normal.dot(Vector3.UP))) + # check if the slope angle exceeds the maximum slope angle + if slope_angle <= max_floor_angle: + var direction_on_surface:Vector3 = normal.cross( + view_direction.cross(normal)).normalized() + apply_central_impulse(mass * (direction_on_surface * ground_speed - linear_velocity) * .1) + if _jumping: - var v:float = sqrt(2. * g * jump_height) - apply_central_impulse(Vector3(0., mass * v, 0.)) + apply_central_impulse(Vector3(0., mass * sqrt(2 * g * jump_height), 0.)) _jumping = false diff --git a/entities/player/player.tscn b/entities/player/player.tscn index 790caa4..cb723af 100644 --- a/entities/player/player.tscn +++ b/entities/player/player.tscn @@ -256,7 +256,6 @@ tp_mesh = NodePath("ThirdPerson/Mesh") third_person = NodePath("ThirdPerson") pivot = NodePath("Pivot") camera = NodePath("Pivot/Camera3D") -max_floor_angle = 80.0 input = NodePath("Inputs") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] @@ -400,27 +399,15 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.6068e-14, -1.19209e-07, 9.5 [node name="sides" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh/Armature/Skeleton3D/sides" index="0"] layers = 2 -[node name="BarrelsInner" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="0"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946) - [node name="BarrelsInner" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/BarrelsInner" index="0"] layers = 2 -[node name="BarrelsOuter" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="1"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946) - [node name="BarrelsOuter" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/BarrelsOuter" index="0"] layers = 2 -[node name="Base" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="2"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946) - [node name="Base" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/Base" index="0"] layers = 2 -[node name="Grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="3"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946) - [node name="Grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/Grip" index="0"] layers = 2 @@ -433,21 +420,12 @@ bones/1/rotation = Quaternion(0, 0.707107, 0.707107, 0) bones/2/rotation = Quaternion(0, 0.707107, 0.707107, 0) bones/3/rotation = Quaternion(0, 0.707107, 0.707107, 0) -[node name="barrel" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="0"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0) - [node name="barrel" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/barrel" index="0"] layers = 2 -[node name="grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="1"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.082471, -0.0653242) - [node name="grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/grip" index="0"] layers = 2 -[node name="main" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="2"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0) - [node name="main" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/main" index="0"] layers = 2