Collision event not triggered

I feel like a jerk right now, because I’ve make a few apps using physics, but now I’m not able to make a simple example like the below trigger an (post) collision event:

\_FULL\_W = display.actualContentWidth \_FULL\_H = display.actualContentHeight local physics = require("physics") physics.start() physics.setDrawMode("hybrid") physics.setGravity(0,0) local postHit = function(e) print("POST HIT") end ballA = display.newImage("ball.png", \_FULL\_W/2, \_FULL\_H\*0.4) ballA.myName = "ballA" ballA.width = \_FULL\_W\*0.2 ballA.height = \_FULL\_W\*0.2 physics.addBody(ballA, "kinematic", { radius=\_FULL\_W\*0.1 } ) ballA.isSensor = true ballB = display.newImage("ball.png", \_FULL\_W/2, \_FULL\_H\*0.7) ballB.width = \_FULL\_W\*0.2 ballB.height = \_FULL\_W\*0.2 ballB.myName = "ballB" physics.addBody(ballB, "dynamic", { radius=\_FULL\_W\*0.1}) ballB.isSensor = true Runtime:addEventListener( "postCollision", postHit ) ballB:setLinearVelocity( 0, -\_FULL\_H\*0.1)

What is the (obvious?) problem here?

Hey, I played around with your code and found out  your problem.

I have never used “postCollision” but i gave it a shot.

So your problem is that “isSensor = true”.

I’m not sure why but when “isSensor = true” then the “postCollision” does not happen.

I commented out the “isSensors” on both objects and the collision fired…

Is there a reason why your using “postCollision”? You could use “collision” and it’ll work way better.!?

Well Good Luck! 

Thanks!

The reason why I use “isSensor” is because I’m only interested to use physics for collision detection. The objects is not supposed to act as physical objects.

Then I use the postCollision, because my understanding was that postCollision is less “messy” than collision, but I think I’ve got that one wrong and that sensor objects don’t generate psotCollision events.

Oh I see.

Well postCollision is alot more noisy then just collision.

Well Good Luck!

That is probably the case, yes. Don’t know I got so caught up in this post business in the first place…  :rolleyes:

Hi @runewinse,

Yes, postCollision is a very specialized and uncommon need. It exists because it can report things that other collision types simply can’t – friction and force of the collision which just occurred, more specifically – but otherwise it’s “noisy” like preCollisions and should only be used in special cases where detecting things like collision force and friction are necessary.

Brent

Hey, I played around with your code and found out  your problem.

I have never used “postCollision” but i gave it a shot.

So your problem is that “isSensor = true”.

I’m not sure why but when “isSensor = true” then the “postCollision” does not happen.

I commented out the “isSensors” on both objects and the collision fired…

Is there a reason why your using “postCollision”? You could use “collision” and it’ll work way better.!?

Well Good Luck! 

Thanks!

The reason why I use “isSensor” is because I’m only interested to use physics for collision detection. The objects is not supposed to act as physical objects.

Then I use the postCollision, because my understanding was that postCollision is less “messy” than collision, but I think I’ve got that one wrong and that sensor objects don’t generate psotCollision events.

Oh I see.

Well postCollision is alot more noisy then just collision.

Well Good Luck!

That is probably the case, yes. Don’t know I got so caught up in this post business in the first place…  :rolleyes:

Hi @runewinse,

Yes, postCollision is a very specialized and uncommon need. It exists because it can report things that other collision types simply can’t – friction and force of the collision which just occurred, more specifically – but otherwise it’s “noisy” like preCollisions and should only be used in special cases where detecting things like collision force and friction are necessary.

Brent