In Godot 4, how do I get the Vector a raycast is pointing towards ?
Basically -raycast.get_collision_normal(), but not necessarily when it is colliding. I am trying to shoot projectiles. Generally how do I get the forward vector of a Node3D, like a camera for example ?
Raycast3D forward vector
- Edited
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.