Seems like this is a common problem, but I couldn’t find the right search terms I guess. Think of the situation in Super Mario Bros where you collect coins. I need to detect when the player touches a coin, remove the coin (and give the player points), but I don’t want the player to bounce off of the coin. He should jump through it.
The docs say this:
“preCollision”: an event type that fires right before the objects start to interact. Depending on your game logic, you may wish to detect this event and conditionally override the collision.
But there is no explanation on how to do this.
This is what I’m attempting (this is in the coin “class”):
local function preCollision( self, event )
obj:removeSelf();
obj = nil;
return true;
end
obj.preCollision = preCollision;
obj:addEventListener( "preCollision", obj );
The coin always gets removed, but sometimes the player bounces off the coin. How can I make sure this doesn’t happen?
I’ve also tried putting the collision detection in the player class, but I still get erratic behavior. Is the only solution to use a global listener? [import]uid: 52127 topic_id: 9727 reply_id: 309727[/import]