Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

event.contact.isEnabled = false doesn't totally let an object "pass through"
Started by lofy Mar 30 2017 02:52 PM

3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 66 posts
  • Corona SDK

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



[TOPIC: post.html]
#2

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 66 posts
  • Corona SDK

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



[TOPIC: post.html]
#3

lofy

[GLOBAL: userInfoPane.html]
lofy
  • Enthusiast

  • 66 posts
  • Corona SDK

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. 



[TOPIC: post.html]
#4

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

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. :)

 

Brent




[topic_controls]
[/topic_controls]