How to make “compound” shapes in pymunk?

As the name says: How can I join / limit 2 bodies or pymunk figures so that they do not act as one single object?
For example, in this case I have a cricket bat consisting of two separate bodies and policies.
I want to join the bat “handle” to the bat “blade” so that I get an object that looks like a bat.

My code is:

### BAT n Co. ### # body format: [vertices, offset, position, mass] bat_bodies_v = [ # bat [[[0, 34], [4, 34], [4, 0], [0, 0]],(-2,-20),(103,190),20], # handle [[[6, 90] , [0, 32] , [0, 17], [6, 0] , [10, 0], [10, 90]],(-5,-20),(100,100),1100] # blade ] bat_bodies = [] for vertices, offset, pos, mass in bat_bodies_v: moment = pm.moment_for_poly(mass,vertices,offset) b = pm.Body(mass,moment) b.position = pos poly = pm.Poly(b, vertices,offset) poly.friction = 0.9 bat_bodies.append(poly) space.add(b,poly) # the closest I got. j1 = pm.constraint.PinJoint(bat_bodies[0].body,bat_bodies[1].body) j2 = pm.constraint.RotaryLimitJoint(bat_bodies[0].body,bat_bodies[1].body,0,0) space.add(j1,j2) 



This ============== becomes =================> strong> This StartEnd
I have a function that drew these green circles in body positions.

+1
python shapes pymunk
Mar 17 '13 at 10:52
source share
1 answer

The best way to create a complex shape in pymunk is to simply snap the shapes to the same body. Therefore, if you do not have a good reason why you want to separate them, I suggest you try and add both forms to the same body.

However, sometimes you may need to do something else, for example, to be able to break objects. I didn’t do anything at all, but Scott (from Chipmunk) writes in this post http://chipmunk-physics.net/forum/viewtopic.php?f=1&t=2420&p=10644&hilit=breakable#p10644 that using PivotJoint and GearJoint can be a good idea to keep both bodies together.

+1
Mar 18 '13 at 16:54
source share



All Articles