Page 1 of 1
n00b question on shapes
Posted: Sat Nov 01, 2008 10:04 am
by raden_muaz
Hi there. I'm quite noob to Chipmunk.
In chipmunk, we can create joints and connect to bodies.
However, in my tank game, I want to attach the tank's track below the tank's base, without the tank's base swinging or sliding.
I tried to attach 2 joints to try making the tank's base static, but I've absolutely no idea - the base still swinging around but this time it remains horizontal.
Is there some other way to make joints static to solve this problem? Or any other solutions?
Re: n00b question: How to create 'static' joint?
Posted: Sat Nov 01, 2008 8:17 pm
by maximile
You can add the two shapes to the same body. You don't need joints at all.
Re: n00b question: How to create 'static' joint?
Posted: Sat Nov 01, 2008 8:47 pm
by raden_muaz
Thanks.
But now I have trouble arranging pm.Poly (polygon shape) onto the body
Does pymunk shapes starts the coordinates from down below or the center?
Right now I create:
1. the tank's base's shape, pm.Poly, sized zero - Vec2d(0,0),
2. the tank's track's shape, pm.Poly, size of the whole sprite
So even the tank is upside-down, the tank will still move as the surface velocity of the track is the whole sprite...
The tank sprite's size is 20x16
I would like to attach shapes proportionally to its size according to this sprite
The tank's track would be at the bottom to 9th pixel (0-9);
While The tank's base would be at 9 pixels from below to the top; (9-16)
Pleas help.

Re: n00b question on shapes
Posted: Sun Nov 02, 2008 6:57 am
by viblo
If im not misunderstanding something, you can do it like:
Code: Select all
ps1 = [(-50, 20), (50,20), (50, -20), (-50,-20)]
ps2 = [(-50, 25), (50,25), (65, 0), (50, -25), (-50,-25), (-65,0)]
mass = 100
moment = 100000
body = pm.Body(mass, moment)
body.position = 250,300
base = pm.Poly(body, ps1, (0,20)) # <- offset half the base height up
base.friction = 0.5
track = pm.Poly(body, ps2, (0,-25)) # <- offset half the track height down
track.friction = 0.5
self.space.add(body, base, track)
Of course it might be better to have the center of gravity (position of body) a bit lower to gain stability, but this was just an example.
Re: n00b question on shapes
Posted: Mon Nov 03, 2008 5:13 am
by raden_muaz
thanks