Page 1 of 1

How to join two bodies so that they keep a constant distance

Posted: Tue Jan 21, 2014 1:54 pm
by tanis
I would like to have two bodies that are joined like this:

Code: Select all

A
|
|
B
and body B should always be at the same distance from A and shouldn't rotate around a pivot. It should always straight down below A. How would you achieve that with Chipmunk?

Re: How to join two bodies so that they keep a constant dist

Posted: Thu Jan 23, 2014 11:04 am
by LegoCylon
A pin joint will maintain constant distance between two bodies. I'd suggest adding one between the centers of each body unless you want B to move up and down as A rotates.

However, this will not guarantee that B will always be below A. For instance, if the forces and velocities of each body do not match then it is likely that they will move out of alignment (although the pin joint will keep their distance constant). I can't think of any combination of existing constraints that is capable of keeping B directly below A. The simplest option would be to make bodies A and B into shapes 1 and 2 of body A (no constraints required since shapes never move relative to their body) and give that body an infinite moment of inertia to prevent torque from rotating it. If it's necessary to keep them as separate bodies then I think you may need to write your own constraint solver (see cpPinJoint.c for an example).

Re: How to join two bodies so that they keep a constant dist

Posted: Thu Apr 23, 2015 1:30 am
by ranaraza
A pin joint will maintain constant distance between two bodies. I'd suggest adding one between the centers of each body unless you want B to move up and down as A rotates.