Physics Not Following User Rotation of Objects in a Group

Hi All:

I have been playing around Adrian Herbez's cannon demo to learn more about dynamic physics properties, but have hit a snag. Specifically, there are two items in a group: the base and the barrel. In the demo, the physics defaults to a generic box for cannonGroup. Unfortunately, that doesn't look too accurate when other objects interact with the cannon.

I have mapped shapes to align with the cannon, but when the user rotates the barrel, the physics (and thus the collision areas) do not change because those are mapped to the group, not the cannon barrel itself. I have tried rotating my defined "cannonShape", but that doesn't appear to be a real object, but part of the group.

I even went a completely different route in creating two separate objects with a joint, but that was a disaster as a weld wouldn't allow the barrel to rotate and pivot wouldn't hold the barrel up (it would just fall to the ground.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function makeCannon()
 
    cannonGroup = display.newGroup()
    cannonBarrel = display.newGroup()
 
    cannon      = display.newImage('graphics/cannon_sm.png', 0, -20)
    cannonBase  = display.newImage('graphics/cannon_base_sm.png', 0, -20)
        cannonShape = { 40,-50, 125,-40, 125,0, -3,10, -0,-10 }
        cannonBaseShape = { 40,10, 90,5, 77,50, -0,50, -5,20, 0,10 }
    
    cannonBarrel:insert(cannon)
    cannon:translate(-52,-20)
    
    cannonBarrel:translate(65,-10)    
    cannonGroup:insert(cannonBarrel)
    cannonGroup:insert(cannonBase)
    
    cannonGroup.rotation = 0
    cannonGroup:translate(75,425)
    
    physics.addBody (cannonGroup, "dynamic",
        {density=3.0, friction=0.5, bounce=0.05, shape=cannonShape},
        {density=3.0, friction=0.5, bounce=0.05, shape=cannonBaseShape})
    cannonGroup.bodyType = "dynamic";
end
views:2057 update:2011/9/28 8:56:32
corona forums © 2003-2011