Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | stolen-biscuit |
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!