Controlling rotation...

Hi,

I'm currently developing a PinBall-like game using Box2D.

In my world, I have bodies that are linked to a path (let's say a spline).
To make a body follow a path, I attach a MouseJoint to it and update the SetTarget() of the MouseJoint each frame with new path coordinates. This seems to work nicely and the collision of bodies with the pinball looks natural as the body is not actually moved by me, but by forces generated through MouseJoint. Is there any better way to do this?

Secondly, I want more control over the rotation of these bodies. For example, I might always want them perpendicular to the spline tangent. I could do this through SetXForm(), but the body would not have an angular velocity. What would be the way to go here?

Thanks in advance,
Zing

P.S. I read in the TODO's you were working on a SplineJoint, but it's not scheduled for release anytime soon right?
You might try using a static body and just moving it according to your path/rotation requirements.

The spline joint will be for things like roller coasters and motion that is not completely constrained.
You might try using two mouse joints: one in the center and one some distance (X) from the center. Then you can set the center mouse joint as you would now (target) and the other to target + X * (cos theta, sin theta), where theta is the desired angle.
Erin Catto wrote:
You might try using a static body and just moving it according to your path/rotation requirements.

Yes I could do this (using SetXForm?), but the body will never have a velocity correct? Meaning, if I'm just moving the body to the right over a straight line and my pinball hits the body, the velocity of the ball will be the same after collision whether it hits the body from the right side or from the left side. Where in reality, the velocity of the ball should be higher after impacting from the right side (as the body is moving in that direction)?
That is correct. To get the desired effect we need a kinematic body: a body with motion that does not react to forces.
kavaler wrote:
You might try using two mouse joints: one in the center and one some distance (X) from the center. Then you can set the center mouse joint as you would now (target) and the other to target + X * (cos theta, sin theta), where theta is the desired angle.

I am now using this and it's working pretty nicely. Thanks for this suggestion 🙂

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