+1 vote

Hi,
I'm using move_and_slide to move my player model (kinematic body) around. I want to prevent it from falling off edges when it's crouching. Is there a simple way to do that?
The collision shape is a capsule with a cylinder at the bottom (so that the player can slide over small things, but doesn't slide off edges).

Thx


Edit:
My code:

func _physics_process(delta : float) -> void:
    # stuff
    process_movement(delta)
    # more stuff

func process_movement(delta : float) -> void:
    # stuff

    # basically the movement code from the Godot FPS tutorial:
    hvel = hvel.linear_interpolate(target, accel * delta)
    vel.x = hvel.x
    vel.z = hvel.z
    vel = move_and_slide(vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))

    # some more stuff
in Engine by (64 points)
edited by

Can you show us the code?

Thx for your reply. I updated my original question. Do you have any ideas how I could prevent move_and_slide from falling off edges?

1 Answer

+4 votes

I don't think there is a setup for this. What I would do is use a RayCast node pointing downward from your character front at the angle I would consider a fall. Then use "not $RayCast.is_colliding" when crouching to detect a drop and stop the movement (don't forget to enable the raycast).

by (283 points)

So there is no built-in way of doing that?

I don't think so, the normal physic behavior is to fall from cliffs, you need to do some work to have a different behavior. I'm not an expert though.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.