#"Hovering" CharacterBody3D

1 messages · Page 1 of 1 (latest)

glass furnace
#

I have a CharacterBody3D set up with a capsule collider.

Movement is handled by changing the velocity (inside _handle_movement) and calling move_and_slide like so:

func _physics_process(delta: float):
    var input_dir := _handle_movement(delta)

    if not is_on_floor():
        velocity.y -= gravity * delta

    var collided := move_and_slide()
    if collided:
        _handle_collisions()

This works great, but I run into a problem with small ledges that are 90 degrees.

---
   |
   ----

☝️ imagine that, but very small. The CharacterBody3D will just hit it and stop immediately instead of "stepping over it". If I make the capsule's radius bigger, it can get over the ledge but that leads to all sort of other issues (too big and doesn't match the visual representation)

What I'd like to do is move the capsule collider up a bit, but still have the CharacterBody3D think it's on the ground when the capsule collider is close enough.

#

Of course, immediately after writing this I discovered SeperationRayShape3D which is exactly what I was looking for.
https://docs.godotengine.org/en/stable/classes/class_separationrayshape3d.html

Adding this as another CollisionShape3D and then moving the capsule collider up worked wonderfully!