pymunk

Pymunk PinJoint with locked rotation with respect to bodies


I'm trying to create a simple chemistry simulator with atoms (circles) and bonds between them. The problem I'm having is that when atoms 'bond' using a pin joint, the circles rotate independently of the joint. I've tried using more than one pin joint, but the molecules end up oscillating, sometimes wildly, as they stretch and correct themselves. I would appreciate any ideas.

Rotating pin joints


Solution

  • My workaround is to create two pinjoints. One from the centres of each of the bodies, and one, very short (0.1), at the contact point of the two bodies. This results in the two bodies (atoms) being very close to each other, but they rotate as a single object. I can set collide_bodies = False for both joints, which reduces processing. There is a little movement when the constrained bodies collide with a third body, but overall the solution works well.