"Passthru" doesn't remove collision with preCollision listener? Animals in game still collide with star objects.

--The Code function addStar(\_x,\_y) local star = display.newImage("star2.png") star.x = \_x; star.y = \_y; star.collType = "passthru" function star:preCollision( event ) event.contact.isEnabled = false end function star:collision(event) if event.contact then event.contact.isEnabled = false; local collideObject = event.other if ( event.phase == "began" ) then event.contact.isEnabled = false; event.contact.isEnabled = false; elseif ( event.phase == "ended" ) then event.contact.isEnabled = false; if(collideObject.collType == "landed\_safely") then -- the collType of the a "safely landed" animal hitting the star, other animals are ignored event.contact.isEnabled = false; --self:fadeOut() timer.performWithDelay(5000, self:removeSelf()); updateScore({star = self}); end print( "ended.") end end end star:addEventListener("collision") star:addEventListener("preCollision") --starDanceA() starGroup:insert(star); physics.addBody(star, "static"); end addStar(325, 200); addStar(225, 275); addStar(425, 275)

Ultimately, I want the stars to be static and to have collision detection, but I don’t want anything to actually bounce off of them. Is there a way to code this using the physics engine that works 100% of the time (my code only works sometimes) without having to code the collision detection “by hand”?

Hi @glchriste,

There are different methods to this, depending on your needs:

  1. If you want the stars to be static objects, with collision detection, but nothing actually bounces (reacts physically) to them, then make them into sensor-type objects.

  2. If you want only some objects to bounce off them, but not everything, then you’ll need to use collision filters.

  3. If you want to selectively void a particular collision between a star and one particular object, then you’ll need to use pre-collision with the physicsContact method.

I can expand on any of these 3 methods if you need…

Take care,

Brent Sorrentino

Making the stars a “sensor” fixed it! Thank you!

Hi @glchriste,

There are different methods to this, depending on your needs:

  1. If you want the stars to be static objects, with collision detection, but nothing actually bounces (reacts physically) to them, then make them into sensor-type objects.

  2. If you want only some objects to bounce off them, but not everything, then you’ll need to use collision filters.

  3. If you want to selectively void a particular collision between a star and one particular object, then you’ll need to use pre-collision with the physicsContact method.

I can expand on any of these 3 methods if you need…

Take care,

Brent Sorrentino

Making the stars a “sensor” fixed it! Thank you!