Get the very first body encountered by RayCast in Godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By roma

Get the very first body encountered by RayCast in Godot? The nearest body? I have RayCast connected to the camera and I want to get the body on which the camera is pointed. I don’t want to use 3D-click, because I want to have a specific distance at which I can click.

Maybe check for when the RayCast is colliding (via is_colliding() in the_physics_process() function) and then use the get_collider() function to get the first object which is colliding? is_colliding() will return true on the first frame it detects a collision.

Ertain | 2023-01-04 18:31