+1 vote

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

I'm using kinetic bodies and sprite 3ds in a 3d environment, and using moveandslide() 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.

in Engine by (15 points)

1 Answer

+1 vote

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.

by (24 points)
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.