Raycast is pointing to target_position
. Since this is relative to position
you can simply normalize it and there's your direction vector. If you need it in global space, you can transform target_position
to global space using Node3D::to_global()
and subtract it from node's global_position
, or alternatively rotate the local direction using node's global_transform.basis
RayCast3D::get_collision_normal()
returns the normal on a collision shape at the point the ray hit it. It has nothing to do with ray direction itself.