Creating Bodies That Don't Rotate

Topics: User Forum
Jun 29, 2007 at 5:02 AM
I'm trying to use Farseer for my sidescroller and it's pretty easy to integrate in. My only question is how can I make my character body not able to rotate? Currently if he hits an edge, his body rotates and causes the collisions to behave weird (when compared to the graphics that is). Thanks for any help and good work on the engine.
Jun 29, 2007 at 5:43 AM
I sort of got it. I created a custom joint:


public class UpVectorJoint : Joint
{
public UpVectorJoint(Body body)
{
Body1 = body;
Body2 = body;
}

public override void PreStep(float inverseDt)
{
Body1.AngularVelocity = 0f;
Body1.ClearTorque();
Body1.Orientation = 0f;
}

public override void Update()
{
Body1.AngularVelocity = 0f;
Body1.ClearTorque();
Body1.Orientation = 0f;
}
}

and combined it with a large rotational drag:


character.body.RotationalDragCoefficient = 5000f;
Joint j = new UpVectorJoint(character.body);
level.simulator.AddJoint(j);

and it seems to work decently. Problem is that when my guy starts running you can see him "tripping" where the box still is trying to rotate around. It makes him jump a little and kind of ruins it. Any ideas?
Coordinator
Jun 29, 2007 at 9:06 PM
Edited Jun 29, 2007 at 9:07 PM
You could try creating an AngularSpring with TargetAngle=0 and setting it to be pretty stiff. You many be able to adjust the parameters enough to simulate a fixed Angle.

The new version has an AngleJoint which allows you to keep a body fixed at any given angle.
Jun 30, 2007 at 6:22 AM
Is it possible to set moment of inertia to infinity? That would easily make an object that can't rotate.
Coordinator
Jul 1, 2007 at 1:11 PM
wow, I never new there was such a property on floats, but I tried this and it seemed to work

agentBody.MomentOfInertia = float.PositiveInfinity;

Thanks BioSlayer. How's your engine coming along??
Jul 1, 2007 at 7:40 PM

crashlander wrote:
Thanks BioSlayer. How's your engine coming along??


It is going good.
I made a demo video to show it off.
You can watch it if you are interested:
http://www.youtube.com/watch?v=Oecv7Cg9lCc
Coordinator
Jul 5, 2007 at 12:35 PM
very nice video. did you add joint limits to a hinge joint for the rigid bodies?