can raycast on multiple elements return which element has been hit ?

is that correct that raycast cannot return which element of a body has been detected along the ray/line ?

i’m trying the example from the doc that works fine except it cannot find out which element so i receive a hit for one object multiple times for each of the element of a body. 

for i,v in ipairs( hits ) do

     print( "Hit: ", i, v.object, v.object.myName,v.object.ip,

           " Position: ", v.position.x, v.position.y, " Surface normal: ", v.normal.x, v.normal.y )

end

is there another way ?

thanks !

Hi @edualc,

I don’t think you can detect the specific element contacted by the ray.

Is your goal to detect the specific element, or to simply not get multiple hits on the same object?

Brent

haha, you are spot on !  

well, right now indeed it’s only to avoid getting multiple hits on the same object ,  but i’m sure there will be sometime where it would be very valuable to know which element !

Hi @edualc,

In this case, I suppose you could gather all hits and “log” them (their data) in a temporary container table or similar. Then after a very short timer (like 10-50 milliseconds), loop through that table and take the proper action on the first, then break the loop so it doesn’t process any of the others. This way you should at least minimize the number of hits on the object to just one.

Hope this helps somewhat,

Brent

thank you Brent,

as I’m searching through the table for the right object, i guess i just need to eliminate the elements of the rejects one at a time.

so it’s no big deal.

However that would be a nice enhancement to be able to know what element is in the way …

Next year when Corona developers are searching for things to do  … :wink:

Hi @edualc,

I don’t think you can detect the specific element contacted by the ray.

Is your goal to detect the specific element, or to simply not get multiple hits on the same object?

Brent

haha, you are spot on !  

well, right now indeed it’s only to avoid getting multiple hits on the same object ,  but i’m sure there will be sometime where it would be very valuable to know which element !

Hi @edualc,

In this case, I suppose you could gather all hits and “log” them (their data) in a temporary container table or similar. Then after a very short timer (like 10-50 milliseconds), loop through that table and take the proper action on the first, then break the loop so it doesn’t process any of the others. This way you should at least minimize the number of hits on the object to just one.

Hope this helps somewhat,

Brent

thank you Brent,

as I’m searching through the table for the right object, i guess i just need to eliminate the elements of the rejects one at a time.

so it’s no big deal.

However that would be a nice enhancement to be able to know what element is in the way …

Next year when Corona developers are searching for things to do  … :wink: