Question

I have two spheres which should always lie at a constant distance from each other. They can move around with all degrees of freedom as long as their distance remains constant. Imagine them to be connected magically by an invisible rod. Various forces are applied on these spheres during a physical simulation to move them around.

I am using two Bullet SphereShapes for the spheres. What kind of constraint (joint) can I use between these two spheres to simulate their constant distance and connection?

It seems to me that I need to introduce a virtual shape (cylinder? capsule?) to connect these two spheres and introduce a spherical constraint (ball-and-socket joint) at each of its two ends to connect to the spheres.

Is there a better way to achieve this setup? What kind of constraint do I use?

Was it helpful?

Solution

I would create my own constraint from Point2PointConstraint (ball and socket).

Line 98 is what needs to be changed. Essentially, you should create a new kind of constraint that knows what distance you want between the two objects. Instead of trying to match pivotAInW and pivotBInW together in world space (depth == 0), the depth variable should be zero when the length of the vector joining pivotAInW and pivotBInW is equal to distance. You may want to safeguard your code against the special case when both pivots are at the same point in space and force a direction in which to apply an impulse, say about the x axis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top