What object did raycast locate?

I read somewhere that there was a similar discussion, but I can’t find it anymore.
Basically I need to know this:
I have objects (sprites) called car1, car2, car3, car4 etc … I have enclosed them all in a group called Car.
Now, with the RayCast beam, I search for the closest object in the Car group.
RayCast finds it and saves me the position (X, Y) of where it is, but I don’t know which object in the Car group it found (i.e., if car1 or car2 or car3 etc …)
I seem to have read that there was a way to know which object RayCast detected, but I can’t find that thread.

does it matter for your actions?
what do you want to do with that information.

why do you use a raycast in the first place, if you just want to pick the nearest object?

Why not use just “pick nearest Object” condition. then you can do whatever with it, like set a variable to its id, or its position, or whatever

1 Like


Thanks Barra. I only know 40% of GDevelop’s potential. Search for the closest object is just what I needed. Now I have to figure out how to change the object variable it found.
I have to give the value of “1” to the object variable “activated” … of the object it has chosen.
“opponents” is a group of objects, but which of them is the closest?

sorry Barre, thanks. It works like this. I have tested it and it works. Thanks so much

1 Like