# In Godot how do you determine if the feet is just on the ground?

Attention Topic was automatically imported from the old Question2Answer platform.
Old Version Published before Godot 3 was released.

In other words how do I determine if the back off the feet is just on the 0 y axis?

One method is to align your object in its own scene so its feet are touching 0 on the origin.

Then whenever accessing the object, its position is always where the bottom of the feet are located.

Another easy method is to use Position3D nodes, and place them where the Y is the bottom of the feet. Name is something obvious like feet_position, and call for its position in code whenever you need to query where the feet are at.

A third is using some offset value. It is the same as Position3D, but you find out the Y distance difference between the origin point of the root node and the feet. Then add or subtract this offset (depending the way you calculate it) from the node position.

Thank you very much

Joe0239 | 2017-12-27 23:11

I have a 3D ray at the bottom of my player primitive. It’s a little hard to see in this picture because it’s perfectly aligned with the axis, but there’s a small RayCast arrow pointing down.

In my code, I grab a reference to this raycast at startup and then keep checking to see if it’s intersecting with something. If it is, I know the object is on the ground. You can do this with the is_colliding() method. Try experimenting with the length of the vector and make sure it’s pointing in the right direction. Here’s the sample code:

``````# In init:

func _process(delta):
...
if !down_ray.is_colliding(): # If we are not on the ground:
acceleration.y = gravity # Start falling.
``````

A minor advantage to this is you can change the length of the ray and its position, so you don’t have to have your object at the origin of the space. This might be considered a downside, but it’s simple to implement on code and it takes advantage of the editor’s visuals.