In my game, I have a physical object (with the property isSensor set to “true”) that I want to overlap some other physical object, and I want to verify it’s collision with other objects and setup some specific actions based on the result. But from time to time, even if I see in the simulator two objects overlapping, the terminal tells me that the collision ended (I made it print the phase status, “began” or “ended”). How can I resolve this issue?
I’ve tried setting the “isBullet” property to “true”, but that hasn’t made much of a difference. (By the way, what does this do exactly?)
I’ve thought about putting the collision listener inside an “enterFrame” listener, so that the collision is verified periodically, but imagine the performance drop resulting from this… It’s not a valid answer.
Any ideas? [import]uid: 13720 topic_id: 5708 reply_id: 305708[/import]
senzor = display.newRect(322, 502, 20, 50)
senzor:setFillColor(255,0,0)
senzor.alpha = 0 -- so that it's invisible
physics.addBody(senzor,"dynamic",{density=0, friction=1, bounce=0.3})
senzor.class = "senzor" -- useful for an if-statement later
senzor.isSensor = true -- so that it doesn't physically interact
senzor.angularDamping = 5000 -- to keep ot from rotating around
And the collision detector…
local touched = false
local function touchedFunc(self, event)
if ( event.phase == "began" ) then
touched = true
elseif ( event.phase == "ended" ) then
touched = false
end
end
senzor.collision = touchedFunc
senzor:addEventListener( "collision", senzor )
And this “sensor” is attached to another object by a “pivot” joint. It’s supposed to detect collision and report it to another function, so that the function does it’s stuff or not. I already tried the isSleepingAllowed one, doesn’t help at all… [import]uid: 13720 topic_id: 5708 reply_id: 19608[/import]