The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have this mechanic where a player can toss a coin and teleport to it, and it's basically just a small rigid body that has a raycaster node on it to it to sense if anything is above it.
I've been using this to point it up:


That code is placed in the process function of the coin, and it mostly works except that the raycast tries to point to somewhere near the origin, resulting in the raycast never perfectly pointing upwards. I've tried a variety of things but I can't get this one line of code to work.

Is there a better solution or some kind of helpful godot function to make this work? I've scoured the docs to no avail.

Godot version 3.2.4 beta 5
in Engine by (35 points)
retagged by

Use the global_position of the coin and add to that distance to look at

$raycast.look_at(coin.global_transform.origin + Vector3(0, 5, 0), Vector3.UP)

If your coin never rotates then there's no reason to use this code at all

the coin does rotate! i tried your code real quick with visible collision shapes and the raycast rotates with the coin. i just figured out a solution, but thank you for your response!

so my code creates a 3d position in the code and then updates it to be above the coin at all times, then i use the cast to function to point at the 3d position node


Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.