Get Actual Collision X,y?

Is it possible to get the actual x, y of a collision of two objects? I know how to get the coordinates of the two respective shapes involved, but how to get the collision point in-between the two?

 

Thanks!

 

Previous discussion:

http://webcache.googleusercontent.com/search?q=cache:TeppklSrMdsJ:developer.coronalabs.com/forum/2011/10/27/get-xy-collision+&cd=1&hl=en&ct=clnk&gl=de (… http://developer.coronalabs.com/forum/2011/10/27/get-xy-collision)

Did you get my response to this? I don’t think you can get the actual point of impact, but by getting the midpoint of both coordinates, that may be your best guess. I am using this technique in my current game and it’s working out pretty good. local midX = ( event.object1.x + event.object2.x ) \* 0.5 local midY = ( event.object1.y + event.object2.y ) \* 0.5

Thanks Beyond!

Did you get my response to this? I don’t think you can get the actual point of impact, but by getting the midpoint of both coordinates, that may be your best guess. I am using this technique in my current game and it’s working out pretty good. local midX = ( event.object1.x + event.object2.x ) \* 0.5 local midY = ( event.object1.y + event.object2.y ) \* 0.5

Thanks Beyond!

In native iOS cocos2d/box2d frameworks you can get collision points and force in each point. Do you (coronalab) plan to implement this functionality? Now it’s really hard issue if you have something more complicated than a circle or a square.

Hi all,

This feature had some issues previously, but it was recently fixed by the engineers and should be available to users soon. I’m not 100% sure that it includes the “force” of each specific point in a multi-point collision, but you should be able to read all points involved in a collision and handle them accordingly.

Best regards,

Brent

You can get the actual collision points in x,y world co-ordinates by setting this:

physics.setReportCollisionsInContentCoordinates( true )

Thank you for the answer! Ani API to do this? Is this some new/hidden property of the event object?

And you’re right, it’s impulse, not force.

Hi @lavmax,

The “corrected” collision point is retrieved in the traditional method… “event.x” and “event.y” (see link below). Now, the point should be correct (it wasn’t reliable before), and you can also “average” the points if two objects collide at multiple points in one collision cycle. We might expand this even further in the future to let you handle each and every point in a multi-point collision individually, but for now, you can get the first collision point or the average point.

http://docs.coronalabs.com/api/event/collision/index.html

Best regards,

Brent

In native iOS cocos2d/box2d frameworks you can get collision points and force in each point. Do you (coronalab) plan to implement this functionality? Now it’s really hard issue if you have something more complicated than a circle or a square.

Hi all,

This feature had some issues previously, but it was recently fixed by the engineers and should be available to users soon. I’m not 100% sure that it includes the “force” of each specific point in a multi-point collision, but you should be able to read all points involved in a collision and handle them accordingly.

Best regards,

Brent

You can get the actual collision points in x,y world co-ordinates by setting this:

physics.setReportCollisionsInContentCoordinates( true )

Thank you for the answer! Ani API to do this? Is this some new/hidden property of the event object?

And you’re right, it’s impulse, not force.

Hi @lavmax,

The “corrected” collision point is retrieved in the traditional method… “event.x” and “event.y” (see link below). Now, the point should be correct (it wasn’t reliable before), and you can also “average” the points if two objects collide at multiple points in one collision cycle. We might expand this even further in the future to let you handle each and every point in a multi-point collision individually, but for now, you can get the first collision point or the average point.

http://docs.coronalabs.com/api/event/collision/index.html

Best regards,

Brent

Which build has this?  The build I am currently using 2013.1135 always returns 0 for event.x and event.y.

since brent’s post was in april and 1135 was released in june i would say its in 1135

Hi @tonygod,

Can you post your collision code? Did you remember to add this line around where you instantiate physics?

[lua]

physics.setReportCollisionsInContentCoordinates( true )

[/lua]

http://docs.coronalabs.com/api/library/physics/setReportCollisionsInContentCoordinates.html

Brent

local function onEm3Collision( event ) print( "onEm3Collision: " .. event.phase ) if ( event.phase == "began" ) then audio.play( sounds["splash"] ) -- TRIGGER THE EMITTERS em3.x = event.x em3.y = event.y Particles.StartEmitter("em3", true) elseif ( event.phase == "ended" ) then bg2:removeEventListener( "collision", onEm3Collision ) waitingForSplash = false end end

I was not previously using physics.setReportCollisionsInContentCoordinates( true ), as I was unaware it was necessary.  The documentation merely states “The x and y position can be influenced by physics.getAverageCollisionPositions() and physics.setReportCollisionsInContentCoordinates().”  

I don’t know what influenced means. For me, it seems to mean I get event.x and event.y coordinates that do not match what I would expect to be the global x/y coordinates when I set it to true and I get 0 when it is not there.

Maybe the fact that I am using scenes or DisplayGroups is affecting this in some way?

Hi @tonygod,

At first glance, it appears you’re not utilizing the proper parameters in the collision listener. Since this is a “local” collision listener (not a Runtime one), the listener supports both “self” and “event”… you’re using just “event”, but that should be the second additional parameter.

Please see the guide on “Local collision listeners” here:

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