event.contact.isEnabled = false doesn't totally let an object "pass through"

I have created an object that I want only my game ball to pass through. 

event.contact.isEnabled = false works if I don’t delete the object the ball is passing through. However I need the object to be deleted after the collision has ended. This has been causing some weird issues where the collisions aren’t reacting as I want. 

local function preCollision( self, event ) local other = event.other if other.name == "ball" then event.contact.isEnabled = false local function deleteListener() display.remove( self ) self = nil end timer.performWithDelay( 40, deleteListener ) end end

I just need the object to act like a sensor for only the ball then delete after the collision. 

Thank you again,

Jarrod

Additionally I’ve tried:

1.) Putting the deleteListener() within a postCollision and that didn’t help.

2.) Setting the brick to an isSensor, but then that causes issues with not allowing other collisions to occur

Unfortunately I’m going to solve this problem by creating two different physics objects attached onto one object, one will be a sensor for the game ball, the other will be for everything else on screen to interact with. I’ll upload my results when I get it to work. 

Hi Jarrod,

This might work for you, without creating two objects:

  1. Add a regular “collision” listener to the object, in addition to the “preCollision” one.

  2. When you get a “preCollision” event on the object – and right after you disable the physics contact – set a property on the object like “self.ballPassingThrough = true”.

  3. In the normal “collision” listener, detect the “ended” phase, and that the “.ballPassingThrough” property is true. If both of these conditions are met, that should indicate that the ball exited (“ended” phase) collision with the object, and then you can delete it.

Not sure if that makes sense or not. Easier to see it in code sometimes, versus describing it. :slight_smile:

Brent

Additionally I’ve tried:

1.) Putting the deleteListener() within a postCollision and that didn’t help.

2.) Setting the brick to an isSensor, but then that causes issues with not allowing other collisions to occur

Unfortunately I’m going to solve this problem by creating two different physics objects attached onto one object, one will be a sensor for the game ball, the other will be for everything else on screen to interact with. I’ll upload my results when I get it to work. 

Hi Jarrod,

This might work for you, without creating two objects:

  1. Add a regular “collision” listener to the object, in addition to the “preCollision” one.

  2. When you get a “preCollision” event on the object – and right after you disable the physics contact – set a property on the object like “self.ballPassingThrough = true”.

  3. In the normal “collision” listener, detect the “ended” phase, and that the “.ballPassingThrough” property is true. If both of these conditions are met, that should indicate that the ball exited (“ended” phase) collision with the object, and then you can delete it.

Not sure if that makes sense or not. Easier to see it in code sometimes, versus describing it. :slight_smile:

Brent