Topic was automatically imported from the old Question2Answer platform.
Asked By
pro
so i want to get the distance btw the raycast and colliding objects as i want to perform some calculations with that value just cant get the right method from raycast to get the job done
It’s a little bit unclear from your question, but I think you’re asking for the length of the ray when it collides.
First, to get the position where the RayCast collided, you use get_collision_point(). Then you find the distance from that point to the raycast’s origin. Keep in mind that the function returns the collision point in global coordinates.
if $RayCast.is_colliding():
var origin = $RayCast.global_transform.origin
var collision_point = $RayCast.get_collision_point()
var distance = origin.distance_to(collision_point)
thanks for the reply was straightforward and giving wat i want thanks