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:

raycast.look_at(coin.translation,Vector3.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 (26 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

3Dpos.translation=coin.translation+Vector3(0,3,0)
raycast.cast_to=to_local(3Dpos.translation)

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 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.