I'm using chipmunk2d for a pretty basic simulation written in golang. I use the go implementation as found here: https://github.com/vova616/chipmunk.
So far I have created segments as a floor and boxes/circles falling down on it, which works perfectly. Then I created a polygon...
The polygon itself is as simple as it gets, just three vertices ({0,0},{0,60},{200,30}) which form a simple triangle. But when it falls on the ground it partly clips through and randomly starts to turn and flip around.
Here is my code:
Code: Select all
verts := []vect.Vect {
vect.Vect{vect.Float(0), 0},
vect.Vect{vect.Float(0), 60},
vect.Vect{vect.Float(200), 30}}
shape = chipmunk.NewPolygon(verts, vect.Vect{-100,-30})
Code: Select all
polybody := chipmunk.NewBody(vect.Float(10), vect.Float(100))
polybody.SetPosition(vect.Vect{vect.Float(500), vect.Float(10)})
polybody.AddShape(polyshape)
space.AddBody(polybody)
I read somewhere that there should be a method to recalculate some value (centroid I think?) but that doesn't seem to exist in the go port... Any other (possibly simple, can even be hacky ) solution?