0 votes

I have the following code for projecting a ray from the camera and detecting any bodies that I intersect. I want to move the $hand scene to the point where the ray intersects:

mouse_pos = get_viewport().get_mouse_position()
ray_origin = $Rotator/Camera.project_ray_origin(mouse_pos)
ray_direction = $Rotator/Camera.project_ray_normal(mouse_pos)

from = ray_origin
to = ray_origin + ray_direction * 2
space_state = get_world().get_direct_space_state()
hit = space_state.intersect_ray(from, to)

if hit.size() != 0:
    $hand.translation = hit.position
    print(hit.position)
else:
    $hand.reset_hand()
    print($hand.translation)

However when I set the hand's translation it disappears from view. How do I get that position of intersection and set another nodes 3D position to that point? Thank you!

in Projects by (19 points)

2 Answers

0 votes
Best answer

So this was actually because $hand.translation is a local translation. I changed it to $hand.global_transform.origin = hit.position and that updated the global coordinates successfully

by (19 points)
0 votes

Just guessing because I don't know what node-types you're working with, but instead of...

$hand.translation = hit.position

... do you instead want ...

$hand.position = hit.position

??

by (9,084 points)

Thanks for taking the time, it wasn't that, but I did find the correct answer which I've left and accepted.

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.

Categories