(Godot v4.2.2)
I’m new to Godot, so I’m trying my best to learn everything on my own, but I’m really stumped on this one. I’m trying to make a crouching mechanic, similar to Minecraft, that prevents the player from falling off any edges and ledges they walk up to. I’m using a singular raycast in the center of the player hitbox to detect when there is no ground under the player (I know this probably isn’t the best idea, but I felt like having an absurd number of raycasts wasn’t a great idea for performance). I thought I could use something like Axis Locks to keep the player on the edge without falling, but not only do I not currently have a way of detecting what axis the ledge is on, but that also prevents you from walking away from the ledge, since it completely locks all movement on that axis. Here’s the code I used if it’s any help:
if is_on_floor() and not crouch_cast.is_colliding(): #if player is ON THE FLOOR and RAYCAST ISN'T TOUCHING THE GROUND
axis_lock_linear_x = true #locks the entire x axis, so I can't move back from the ledge either
else:
crouch_cast.enabled = false #disables the raycast
axis_lock_linear_x = false
axis_lock_linear_z = false
If anyone knows a good way to do this, or if it’s even possible, please help! Thanks.