Detecting object height relative to player, to step or climb?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By funkyfresh

Hi, another question as I’m getting started on Godot.

I’m using kinetic bodies and sprite 3ds in a 3d environment, and using move_and_slide() to move.

However, I’m unsure how to deal with obstacles other than requiring you to jump over them. Is there a simple way to detect the height of an object you bump into? Like using a ray to compare y values?

Ideally, I’d ignore a little height and step over normally, run a step animation and go up a certain height, and climb up a certain height.

I’m still not exactly sure how to interact with objects on the fly like that, rather than attaching scripts to every single set of steps or wall you can climb?

can I simply query the transform y value, will that know the “top” of the object? I’m still new with the script and don’t quite know all my options yet.

:bust_in_silhouette: Reply From: Helgrind

There are several ways to do it.

One approach is to make theses objects collision shapes slides. For instance, stairs could be represented as a slope.

Another simple approach is to make the player’s feet’s collision shape a round shape. The con is that your player might slide a bit more.

Another approach I used in my game is to use 2 raycasts.
One is higher than the other, this represents the “step” height.
Then I do something like :

if bottom_ray_cast.is_colliding() and !top_raycast.is_colliding():
   velocity.y = (some offset, can be the distance between the collision points)

I don’t know if it’s the best way to do it, but it’s a solution.