Collision Coordinates

Is there any way of getting the exact x and y values of a collision? I have 2 objects colliding, and I want to know the exact coordinates where the 2 objects meet, so I can create something in that exact location. Is there any way? [import]uid: 53195 topic_id: 32541 reply_id: 332541[/import]

Also, they’re multi-body objects, made of many small bodies, so finding out which of the bodies has been hit would work as well [import]uid: 53195 topic_id: 32541 reply_id: 129359[/import]

Also, they’re multi-body objects, made of many small bodies, so finding out which of the bodies has been hit would work as well [import]uid: 53195 topic_id: 32541 reply_id: 129359[/import]

Hello,
You can determine which of the body “pieces” collide by checking their ID according to the order in which you declared the body pieces. But unfortunately at this time, you can’t get the exact X/Y location of a collision.

Best regards,
Brent [import]uid: 9747 topic_id: 32541 reply_id: 129425[/import]

event.x and event.y gives you the coordinates of the collision. However, there is probably still a bug in it so it doesn’t work every time. I have used it in two games, but both times I needed to create some workarounds to filter it out everytime it gives the wrong coordinates. In my cases it was always exactly correct or way off. [import]uid: 13507 topic_id: 32541 reply_id: 129435[/import]

yes this bug really need to be fixed soon!

@polygonblog
would you like to share how you did this filtering? [import]uid: 13632 topic_id: 32541 reply_id: 129452[/import]

Hello,
You can determine which of the body “pieces” collide by checking their ID according to the order in which you declared the body pieces. But unfortunately at this time, you can’t get the exact X/Y location of a collision.

Best regards,
Brent [import]uid: 9747 topic_id: 32541 reply_id: 129425[/import]

event.x and event.y gives you the coordinates of the collision. However, there is probably still a bug in it so it doesn’t work every time. I have used it in two games, but both times I needed to create some workarounds to filter it out everytime it gives the wrong coordinates. In my cases it was always exactly correct or way off. [import]uid: 13507 topic_id: 32541 reply_id: 129435[/import]

yes this bug really need to be fixed soon!

@polygonblog
would you like to share how you did this filtering? [import]uid: 13632 topic_id: 32541 reply_id: 129452[/import]

Yes, it’s bugged for me 90% of the time, but the workaround would be greatly appreciated btw ^^

Also, Brent Sorrentino, how do I check which one of the body pieces collided? Could you provide a sample code where you check for the collided body pieces? or atleast, where can I read about it? [import]uid: 53195 topic_id: 32541 reply_id: 129555[/import]

Yes, it’s bugged for me 90% of the time, but the workaround would be greatly appreciated btw ^^

Also, Brent Sorrentino, how do I check which one of the body pieces collided? Could you provide a sample code where you check for the collided body pieces? or atleast, where can I read about it? [import]uid: 53195 topic_id: 32541 reply_id: 129555[/import]

Hi @alfgago,
Certainly: the details are described in the following link under the subheader “Collisions with multi-element bodies”. The entire document is worth reading, actually, as it contains many notes on collisions.

http://developer.coronalabs.com/content/game-edition-collision-detection

Best regards,
Brent
[import]uid: 9747 topic_id: 32541 reply_id: 129614[/import]

Now, having this index, is there any way to find the actual body position? like a object[event.selfElement], where it gives me the physical body with that index, so I can find it’s x and y?

Thank you for the help so far! ^^ [import]uid: 53195 topic_id: 32541 reply_id: 129631[/import]

My simple workarounds don’t produce the correct collision coordinates. They just skip the wrong ones. In my games, I wanted to apply some sparks effects in the location where a vehicle collides with other objects. It was just a visual effect so it was ok if the sparks didn’t appear in every collision. Therefore I was able to create two workarounds:

  1. In the first game, the collision was sometimes on the wrong side of the vehicle so I just compared the coordinates of the collision objects and used simple if-then construct to avoid the sparks altogether in the case of erroneous collision coordinates.

  2. In the second game, the erroneous collision location was always outside the physics body. In that case I just filtered it out every time it was too far away from the center of my physics body.

It was pretty straightforward to filter out the erroneous collision coordinates. The first thing is to visually identify where the erroneous collision location(s) is/are.

I really wish this would be fixed soon! [import]uid: 13507 topic_id: 32541 reply_id: 129634[/import]

Hi @alfgago,
Certainly: the details are described in the following link under the subheader “Collisions with multi-element bodies”. The entire document is worth reading, actually, as it contains many notes on collisions.

http://developer.coronalabs.com/content/game-edition-collision-detection

Best regards,
Brent
[import]uid: 9747 topic_id: 32541 reply_id: 129614[/import]

@polygonblog
thanks.
I did similar workarounds, but this bug really limits the use of collision coordinates, which is a shame because we could do cool stuff with it if it were working properly. [import]uid: 13632 topic_id: 32541 reply_id: 129650[/import]

Now, having this index, is there any way to find the actual body position? like a object[event.selfElement], where it gives me the physical body with that index, so I can find it’s x and y?

Thank you for the help so far! ^^ [import]uid: 53195 topic_id: 32541 reply_id: 129631[/import]

My simple workarounds don’t produce the correct collision coordinates. They just skip the wrong ones. In my games, I wanted to apply some sparks effects in the location where a vehicle collides with other objects. It was just a visual effect so it was ok if the sparks didn’t appear in every collision. Therefore I was able to create two workarounds:

  1. In the first game, the collision was sometimes on the wrong side of the vehicle so I just compared the coordinates of the collision objects and used simple if-then construct to avoid the sparks altogether in the case of erroneous collision coordinates.

  2. In the second game, the erroneous collision location was always outside the physics body. In that case I just filtered it out every time it was too far away from the center of my physics body.

It was pretty straightforward to filter out the erroneous collision coordinates. The first thing is to visually identify where the erroneous collision location(s) is/are.

I really wish this would be fixed soon! [import]uid: 13507 topic_id: 32541 reply_id: 129634[/import]

@polygonblog
thanks.
I did similar workarounds, but this bug really limits the use of collision coordinates, which is a shame because we could do cool stuff with it if it were working properly. [import]uid: 13632 topic_id: 32541 reply_id: 129650[/import]

Hi @ alfgago,
I don’t think there’s a way to pinpoint the location of a specific body part using only the event handler. However, you could do this mathematically based on the core X/Y of the object (both of which you can access at any time). It would take some up-front effort when you create the body, but seemingly it’s possible. Basically, you’d need to set “offset” coordinates for each body part in relation to 0,0 at the overall body center. Then, you could use those coordinates plus basic trigonometry (assuming the body might rotate) to determine where the body part is during a collision.

@polygonblog,
Just curious, is there an official bug report on file for this? If not, could you possibly create a bare-bones simple test instance of it, showing the bug? I could then try to push its priority and urge the Corona engineers to investigate and hopefully fix it.

Brent Sorrentino
[import]uid: 9747 topic_id: 32541 reply_id: 129679[/import]