Raycast returns object it last collided with

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cryingpants
:warning: Old Version Published before Godot 3 was released.

My raycast node returns the same object it collided with last when it’s not colliding with anything. Is there any solution I can use? Am I missing something?

Difficult to help if you don’t show the example scene and the script to check the collision.

genete | 2016-09-03 22:38

I moved answer to comment because it’s actually not an answer.

volzhs | 2016-09-04 16:16

As this document says, http://docs.godotengine.org/en/latest/classes/class_raycast.html
RayCast.get_collider() just returns only one Object

According to https://github.com/godotengine/godot/blob/3a70d4a072fa170ae927e2b416861ccd395f92d2/servers/physics/space_sw.cpp#L50-L138
yes, it just try to find last colliding object and return it.

This can be fixed somehow, but it will break compatibility.
I suggest you to report this issue on github.
Issues · godotengine/godot · GitHub
Probably, it could be fixed in Godot 3.0

volzhs | 2016-09-04 16:27

:bust_in_silhouette: Reply From: linuxfree

yes return object collided with raycast all fine