feat: implement ground movement state with integrated jumping, sliding, and stair-stepping logic

This commit is contained in:
DottsGit
2026-06-15 15:58:16 -04:00
parent abddc0c1cc
commit 3afc213b3a
2 changed files with 30 additions and 12 deletions
+11 -5
View File
@@ -101,9 +101,15 @@ func update(delta: float) -> void:
var space_state = player.get_world_3d().direct_space_state
var feet_y = player.global_position.y - (machine.original_capsule_height / 2.0)
# Raycast down from above the step
var fwd = wish_dir.normalized()
var ray_start = player.global_position + fwd * 0.65
# Raycast down from above the step using wall contact point
var push_dir = -col.get_normal()
push_dir.y = 0.0
if push_dir.length_squared() < 0.01:
push_dir = wish_dir.normalized()
else:
push_dir = push_dir.normalized()
var ray_start = col.get_position() + push_dir * 0.1
ray_start.y = feet_y + max_step_height + 0.1
var ray_end = ray_start - Vector3.UP * (max_step_height + 0.2)
@@ -125,13 +131,13 @@ func update(delta: float) -> void:
# Check if there is enough space to move forward after stepping up
var test_transform = player.global_transform
test_transform.origin.y += step_height + 0.05
if not player.test_move(test_transform, fwd * 0.15):
if not player.test_move(test_transform, push_dir * 0.15):
# We can safely step up
player.global_position.y += step_height + 0.01
if player.head_pivot and player.head_pivot.has_method("add_step_offset"):
player.head_pivot.add_step_offset(-(step_height + 0.01))
# Push slightly forward to get onto the step
player.global_position += fwd * 0.1
player.global_position += push_dir * 0.1
# Restore horizontal velocity that was lost from hitting the wall
player.velocity.x = hvel.x
player.velocity.z = hvel.z