0 votes

enter image description here

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

in Engine by (194 points)
edited by

3 Answers

+1 vote

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.

by (5,232 points)

Thank you very much :)

0 votes

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.

Player Hierarchy

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:
onready var down_ray = get_node("DownRay")

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.

by (16 points)
0 votes

Why not simply use a collider or getting the global position of the object??

by (26 points)

Sometimes the raycast is useful to check if the character/player/object isn't "flipped" and touching the ground. For example, if I use a car as the collider, it could show that the car is on the ground even when upside-down. Same for the player, it might consider the player on the ground even if it is colliding with a wall or something.

The global position is another way out, however it wouldn't work too well if you have more "floors" on your level.

EDIT: Nevermind, I had misread it and thought that the OP wanted to check if the player was on the ground, but as he wants to know the axis of his feet, the Position3D solution works just fine.

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.