Hi,
I have recently learned more about the physics by watching the video tutorial “Zero to Angry Birds in 30 minutes” and it was great! Now I am trying to learn about the collision and am a little confused. I was going through the documentation and saw the code below. My question is how exactly do I use this to check if any object hit a character? For example, if I made an Angry Birds type game how can i tell if any of the blocks hit the character? Will the example below fire every time one object hit another? And if so, I assume I can tell if the character was hit if it is either the object1 or object2 name right?
I’m just trying to see if I understand this or if I’m way off. Thanks!!
Warren
local crate1 = display.newImage( "crate.png", 100, 200 )
physics.addBody( crate1, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate1.myName = "first crate"
local crate2 = display.newImage( "crate.png", 100, 120 )
physics.addBody( crate2, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate2.myName = "second crate"
local function onCollision( event )
if ( event.phase == "began" ) then
print( "began: " .. event.object1.myName .. " & " .. event.object2.myName )
elseif ( event.phase == "ended" ) then
print( "ended: " .. event.object1.myName .. " & " .. event.object2.myName )
end
end
Runtime:addEventListener( "collision", onCollision )
[import]uid: 184193 topic_id: 34209 reply_id: 334209[/import]