b2PrismaticJoint that doesn't stop rotation

I want to add a tire to a car that can move freely along an axis, and is held in position by a b2DistanceJoint that is configured to act as a spring, causing the car to have suspension. The prismatic joint is what I would want to use, except that it doesn't allow relative rotation of the bodies. Could a m_allowRotation and accompanying logic be added?
could you not add a revolute joint to the prismatic joint?

prismatic joint between car body and axle body
revolute joint between axle body and wheel body

just means you need to have a dummy axle body.

also, maybe a spring would work better than a prismatic joint for suspension?
The dummy body solution could turn out OK, except that I think that I will need to assign a mass to it that is significant enough to keep the wheels where they should be, since a joint applies forces and impulses to both bodies, and the weight of the axle is required to work out the final wheel location. I cannot just use a spring or even a pair of springs because a wheel on a real car is constrained to move up and down vertically, with suspension applying a spring force to it. That vertical constraint will need a prismatic joint, but not blocking the wheel from rotating.
Hi Erin,

Given the instability and mushiness that occurs from composing primitive joint types, is this recommended practice in Box2D as opposed to creating a b2GrooveJoint or a prismatic joint that can optionally allow rotation? I'm willing to just dive into b2PrismaticJoint myself, but I'm unsure if its possible for me to make some hairy bugs that are too complex me to fix at that point, since I already feel challenged just to modify the joint in the ways that I need.

-Tim
Have you tried using a prismatic + revolute joint? Make the axle shape the same size and density as the wheel, but filter out all collisions with it.

chassis body -- <prismatic joint> -- axle body -- <revolute joint> -- wheel body

You might consider using ray cast wheels and faking the rolling motion somehow. That's how most vehicles are built in games.
I almost have a prismatic joint that allows rotations working, but I don't really understand the order of operations or how the block solvers work.

In b2PrismaticJoint::SolvePositionConstraints:

Code:
#ifndef DISABLE_PRISMATIC_ROTATION
   C1.y = 0.0f;
#else
   C1.y = a2 - a1 - m_refAngle;
#endif


I think that code is solid, since an angle difference of 0 means that no angular position correction will ever get applied.

The velocity one is causing more problems, and leading to massive instability, so I might be in over my head.

Code:
void b2PrismaticJoint::SolveVelocityConstraints(const b2TimeStep& step)
{
   b2Body* b1 = m_body1;
   b2Body* b2 = m_body2;

#ifndef DISABLE_PRISMATIC_ROTATION
   b2Vec2 v1 = b1->m_linearVelocity;
   float32 w1 = 0.0f;
   b2Vec2 v2 = b2->m_linearVelocity;
   float32 w2 = 0.0f;
#else
   b2Vec2 v1 = b1->m_linearVelocity;
   float32 w1 = b1->m_angularVelocity;
   b2Vec2 v2 = b2->m_linearVelocity;
   float32 w2 = b2->m_angularVelocity;
#endif
.
.
.
#ifndef DISABLE_PRISMATIC_ROTATION
   b1->m_linearVelocity = v1;
   b2->m_linearVelocity = v2;
#else
   b1->m_linearVelocity = v1;
   b1->m_angularVelocity = w1;
   b2->m_linearVelocity = v2;
   b2->m_angularVelocity = w2;
#endif
}


I prefer to build a joint that is a subset of the prismatic joint's functionality (prismatic minus rotation constraint), than to combine joints using intermediate bodies. The vehicle is the user's main interaction with the game environment, and will be subject to a wide variety of forces. I'm afraid that a joint composed of two joints and an intermediate body will be too unstable to be well tuned in all circumstances. Erin, I can do the heavy lifting to get this working if you can help me understand a few things as I encounter them.
I recommend copying the joint and making a new one from it.

A lot of the complexity of the prismatic joint comes from the limit and motor. Do you need these?

A prismatic constraint without the rotation part means that a point on body2 is constrained to move along a line fixed in body1. Is this what you want?

Are you looking to have a rotational motor/limit? This would add a lot of complexity.
I don't need the motor or the limit. There is a fairly stiff spring that should keep body2 close to the correct position along the path relative to body1. I don't like being this helpless, but I'm not sure how to proceed on my own.
Read these presentations:

http://www.gphysics.com/downloads

Post again if you still need help.
So the Jacobian is just a matrix that converts between cartesian and constraint space. For this constraint, I only care about one dimension. How do I "project some dimensions to zero"?

Is this a valid process:

1) Convert body2's constraint point into constraint space (still has two dimensions???).
2) Find nearest point on the constraint axis.
3) Convert that nearest point on the constraint axis to body1's local space.
4) Treat that point as R1, finding linear velocity of that particle (treat as particle on body1).
5) Treat the point from step 1 as R2, finding linear velocity of that particle (treat as particle on body2).
6) Difference in velocities of R1,R2 cross constraint axis = velocity amount that needs correcting.
7) Sequential impulses + some sort of position correction, since the uncorrected velocity prior to this constraint put position out of constraint.

I need help confirming that steps 1-6 are correct and I don't understand what to do with step #7. Thank you so much for your help Erin.

-Tim Kerchmar

Original thread: https://box2d.org/forum/viewtopic.php?t=1267