n00b question on shapes

Official forum for the Chipmunk2D Physics Library.
Post Reply
raden_muaz
Posts: 9
Joined: Sat Nov 01, 2008 9:52 am
Contact:

n00b question on shapes

Post 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?
Last edited by raden_muaz on Sun Nov 02, 2008 2:04 am, edited 1 time in total.
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: n00b question: How to create 'static' joint?

Post by maximile »

You can add the two shapes to the same body. You don't need joints at all.
raden_muaz
Posts: 9
Joined: Sat Nov 01, 2008 9:52 am
Contact:

Re: n00b question: How to create 'static' joint?

Post 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
Image


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. :(
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: n00b question on shapes

Post 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.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
raden_muaz
Posts: 9
Joined: Sat Nov 01, 2008 9:52 am
Contact:

Re: n00b question on shapes

Post by raden_muaz »

thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests