physics body collision trigger emitter

I have a working emitter (bomb explosion from sample)… I can fire it when a function i have has one object colliding with another…

It fires in the spot specified by the emitter…

I want it to fire at the point of impact of the two objects… How is that done?

Matt [import]uid: 18783 topic_id: 33811 reply_id: 333811[/import]

Unfortunately, getting the point of collision from Corona is not possible right now. You could work it out if your shapes are relatively circular.

If your physics bodies are not circular you have a problem - the Box2D engine does provide this information, but it’s not exposed in CoronaSDK so far, so there is a performance limitation in calculating the collision, ie: you do it longhand.

I have been intending to write some code for the Exchange, but here is my basic premise:

Assuming the collision is not a ‘preCollision’ - it must already be happening - loop through each line which forms the physics shape of your physics bodies. For each pair of lines check that they intersect with each other. If they do, that’s where the collision is happening.

The loop is basic, but the line intersection check can be performed using the ‘doLinesIntersect’ function from my math library:

http://developer.coronalabs.com/code/maths-library

I’ve got more useful code here:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html [import]uid: 8271 topic_id: 33811 reply_id: 134385[/import]

I have an object I am sliding back and forth with my finger… when another object hits it I am able (without particle candy) fire off a eventSound with no problem so I am able to tell when they hit… just trying to make the explosion happen when those two object come in contact… I tried adding the start emitter code to the function that is accurately handling the collision event. It makes the explosion go off - but it is at the x,y coordinate of the emitter… got to be a way to tell the emitter to fire at the current x,y of the object being hit or the object doing the hitting…

Matt
[import]uid: 18783 topic_id: 33811 reply_id: 134387[/import]

Got it…

explosionEmitter = Particles.GetEmitter(“explosionEmit”)
explosionEmitter.x = event.object2.x
explosionEmitter.y = event.object2.y
Particles.StartEmitter(“explosionEmit”, true) [import]uid: 18783 topic_id: 33811 reply_id: 134394[/import]

Unfortunately, getting the point of collision from Corona is not possible right now. You could work it out if your shapes are relatively circular.

If your physics bodies are not circular you have a problem - the Box2D engine does provide this information, but it’s not exposed in CoronaSDK so far, so there is a performance limitation in calculating the collision, ie: you do it longhand.

I have been intending to write some code for the Exchange, but here is my basic premise:

Assuming the collision is not a ‘preCollision’ - it must already be happening - loop through each line which forms the physics shape of your physics bodies. For each pair of lines check that they intersect with each other. If they do, that’s where the collision is happening.

The loop is basic, but the line intersection check can be performed using the ‘doLinesIntersect’ function from my math library:

http://developer.coronalabs.com/code/maths-library

I’ve got more useful code here:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html [import]uid: 8271 topic_id: 33811 reply_id: 134385[/import]

I have an object I am sliding back and forth with my finger… when another object hits it I am able (without particle candy) fire off a eventSound with no problem so I am able to tell when they hit… just trying to make the explosion happen when those two object come in contact… I tried adding the start emitter code to the function that is accurately handling the collision event. It makes the explosion go off - but it is at the x,y coordinate of the emitter… got to be a way to tell the emitter to fire at the current x,y of the object being hit or the object doing the hitting…

Matt
[import]uid: 18783 topic_id: 33811 reply_id: 134387[/import]

Got it…

explosionEmitter = Particles.GetEmitter(“explosionEmit”)
explosionEmitter.x = event.object2.x
explosionEmitter.y = event.object2.y
Particles.StartEmitter(“explosionEmit”, true) [import]uid: 18783 topic_id: 33811 reply_id: 134394[/import]