Hi Rich,
Here’s a sample project for you, showing how it works. Please turn on “hybrid” physics view to see what’s going on.
The idea here is, when you create a multi-element body, those bodies will be assigned a number based on the order in which you add them to the overall body. You can then use these values to “turn off” one of the parts in the pre-collision listener… you’ll need to figure out a bit more enhanced logic than what I’ve provided, but it should be simple enough. Anyway, once you have that detection working, the use of the event.contact.isEnabled (a PhysicsContact feature) boolean determines if the actual collision happens or not.
So, check it out and see how it works for you. If you have any other questions, let me know.
Brent
[code]
local physics = require(“physics”) ; physics.start()
physics.setGravity( 0.0, 2.0 ) ; physics.setDrawMode( “hybrid” )
local function ballCollide( self, event )
–print(event.otherElement)
if( event.otherElement == 1 ) then
event.contact.isEnabled = false
end
return true
end
local box = display.newRect(0,0,200,100) ; box:setFillColor(255,0,0)
local bodyPart1 = { -150,0, 20,0, 20,34, -150,34 }
local bodyPart2 = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
physics.addBody( box, “static”,
{ density=3.0, friction=0.5, bounce=0.1, shape=bodyPart1 },
{ density=4.0, friction=0.5, bounce=0.1, shape=bodyPart2 }
)
box.x = 140 ; box.y = 200
local ball = display.newCircle( testGroup, 150, 700, 10 ) ; ball:setFillColor(255,100,100)
physics.addBody( ball, “dynamic”, { density=1.0, friction=0.3, bounce=0.4, radius=10 } )
ball.preCollision = ballCollide ; ball:addEventListener( “preCollision”, ball )
ball.x = 120 ; ball.y = 0
[/code] [import]uid: 200026 topic_id: 34019 reply_id: 135365[/import]