How to create a character with multi-bodies (not multi elements)

 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?

Hi @khanh.dq,

At this time, when dealing with physics, you can’t move an entire display group of physics objects independently of other display groups that contain physics objects. Or to clarify, you can move them, but if those groups have objects which can collide with each other, moving the groups separately will cause the collisions to malfunction, because Box2D calculates the collision math with the assumption that the objects share the same overall coordinate space.

As for creating characters with multiple limbs and such, you may consider attaching the different parts with physics joints OR using a 3rd-party utility like Spine. Do you have experience with either of these?

Take care,

Brent

 Thank Brent.

 I only have little experience with physics joints. My game’s using Spine, so could you send me links or documents about using physics with Spine?

Hi @khanh.dq,

I’ve only experimented with Spine a little, so I’m not a trained expert on it. I think you’ll find a lot of good answers in the Spine sub-forum here:

http://forums.coronalabs.com/forum/593-spine/

Take care,

Brent

Hi @khanh.dq,

At this time, when dealing with physics, you can’t move an entire display group of physics objects independently of other display groups that contain physics objects. Or to clarify, you can move them, but if those groups have objects which can collide with each other, moving the groups separately will cause the collisions to malfunction, because Box2D calculates the collision math with the assumption that the objects share the same overall coordinate space.

As for creating characters with multiple limbs and such, you may consider attaching the different parts with physics joints OR using a 3rd-party utility like Spine. Do you have experience with either of these?

Take care,

Brent

 Thank Brent.

 I only have little experience with physics joints. My game’s using Spine, so could you send me links or documents about using physics with Spine?

Hi @khanh.dq,

I’ve only experimented with Spine a little, so I’m not a trained expert on it. I think you’ll find a lot of good answers in the Spine sub-forum here:

http://forums.coronalabs.com/forum/593-spine/

Take care,

Brent