Hi everyone.
I want to make a charater with multi-bodies. Example: a man with two hand and two leg bodies. I wanna do that to make my character can kick, punch v.v.v., and I can detect exactly which his body part collides with enviroment. If I use multi-elements, I can’t make those elements move same as the objects move ( likes when my character punches, I want the hand’s body moves). I create character as a display group, and insert all his parts in, then create body for every part. The problem is: If I only move his parts, like rotation hands, move legs, v.v.v. All bodies’ moves and the collision work correctly. But If I move the character, although I see that physics draws that the bodies move, the collision doesn’t work correctly.
Let’s see Corona “CollisionDetection” sample. I modified its main.lua like that:
local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local physics = require( "physics" ) physics.setDrawMode( "hybrid" ) physics.start() physics.setGravity(0,0) local sky = display.newImage( "bkg\_clouds.png", centerX, 195 ) local ground = display.newImage( "ground.png", centerX, 445 ) ground.myName = "ground" physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } ) local character = display.newGroup() local hand = display.newImage( "crate.png", 180, -50 ) character:insert(hand) hand.myName = "object hand" character.myName = "character" physics.addBody( hand, { density=3.0, friction=0.5, bounce=0.3 } ) local function onGlobalCollision( event ) if ( event.phase == "began" ) then print( "Global report: " .. event.object1.myName .. " & " .. event.object2.myName .. " collision began" ) elseif ( event.phase == "ended" ) then print( "Global report: " .. event.object1.myName .. " & " .. event.object2.myName .. " collision ended" ) end print( "\*\*\*\* " .. event.element1 .. " -- " .. event.element2 ) end Runtime:addEventListener( "collision", onGlobalCollision ) --no collision transition.to(character,{ y = character.y + \_H, time = 2000 }) --[[has collision transition.to(hand,{ y = hand.y + display.contentHeight, time = 2000 })]]
As you can see if you run this code, If I transition the character, no collision happens, although their bodies overlap.
So how can I get my purpose?