get x,y of a collision

hy,

is there a way to find the exact x,y of a collision? i can get the event.target and the event.other, but i a want the x,y where they collided?

thks [import]uid: 92107 topic_id: 17010 reply_id: 317010[/import]

Sure

[code]

local function onLocalCollision(event)
local obj1 = event.object1
local obj2 = event.object2

–Began
if event.phase == “began” then
print(obj1.x)
print(obj2.x)

–Ended
elseif event.phase == “ended” then

end

return true
end

Runtime:addEventListener(“collision”, onLocalCollision)
[/code] [import]uid: 84637 topic_id: 17010 reply_id: 64360[/import]

If the two objects are circular then the radius is the same all the way around (unlike squares 3) so find the x,y of the first object, the x,y object of the second object and then the average of the two.

(obj1.x + obj2.x)*.5 = average.x
(obj1.y + obj2.y)*.5 = average.y

average.x, average.y = collision point. [import]uid: 79135 topic_id: 17010 reply_id: 64467[/import]

Danny’s code above will give you the coordinates of the objects involved in the collision, however if you want the coordinates of the actual collision it becomes a little trickier.
In fact, I don’t think you can. If you need to determine if a specific part of an object has been hit you’ll need to create a ‘Complex Body’ with multiple parts and examine the event for which part has been hit.

You can get more info here:
http://developer.anscamobile.com/content/game-edition-physics-bodies#Complex_body_construction

http://developer.anscamobile.com/content/game-edition-collision-detection
[import]uid: 70847 topic_id: 17010 reply_id: 64475[/import]

I was exactly searching for that some days ago, since I wanted to make some dust particles to be created and falling when a ball hits the wall - therefore I would need the collision position, not the coordinates of those two objects.

So if there’s an easy way to make that happen - let me know [import]uid: 13097 topic_id: 17010 reply_id: 64504[/import]

@xxxfanta

My feeling is that you could use the ball’s coordinates, motion vector and radius to determine how the dust should fall? [import]uid: 70847 topic_id: 17010 reply_id: 64509[/import]