This project has moved and is read-only. For the latest updates, please go here.

Suspension and LineJoint in Farseer 3.3.1

Topics: User Forum
Mar 10, 2012 at 9:29 AM

Hi all,

I want to use farseer physics in my project, but i'm already stuck. I am trying to build a simple car. As suggested in other posts I have looked at the GameDemo1 sample, but I am unable to produce the result I need in my own project. I seem to be misunderstanding the axis variable in a LineJoint. If I change the Y value of the axis from -1.5 to -1.6 the car becomes completely unstable and just does random stuff (to me) in the air. It appears that I just don't understand the LineJoint (or maybe Joints in general). Can anybody help me out?

_hzFront = 8.5f;
_hzBack = 5.0f;
_zeta = 0.85f;
_maxSpeed = 50.0f;

Vertices vertices = new Vertices(8);
vertices.Add(new Vector2(-62.5f, 2f));
vertices.Add(new Vector2(-59.375f, -11.5f));
vertices.Add(new Vector2(-14.5f, -23f));
vertices.Add(new Vector2(11.5f, -23f));
vertices.Add(new Vector2(62.5f, -4.25f));
vertices.Add(new Vector2(62.5f, 5.125f));
vertices.Add(new Vector2(57.5f, 8.25f));
vertices.Add(new Vector2(-56.25f, 8.75f));
PolygonShape chassis = new PolygonShape(vertices, 2f);
_car = new Body(game.World);
_car.BodyType = BodyType.Dynamic;
_car.Position = new Vector2(200.0f, 50.0f);

_wheelBack = new Body(game.World);
_wheelBack.BodyType = BodyType.Dynamic;
_wheelBack.Position = new Vector2(-40f, 10) + _car.Position;
Fixture fix = _wheelBack.CreateFixture(new CircleShape(12.5f, 20f));
fix.Friction = 0.9f;
_wheelFront = new Body(game.World);
_wheelFront.BodyType = BodyType.Dynamic;
_wheelFront.Position = new Vector2(40f, 10) + _car.Position;
_wheelFront.CreateFixture(new CircleShape(12.5f, 20f));
Vector2 axis = new Vector2(0, -1.5f);
_springBack = new LineJoint(_car, _wheelBack, _wheelBack.Position, axis);
_springBack.MotorSpeed = 0.0f;
_springBack.MaxMotorTorque = 20.0f;
_springBack.MotorEnabled = true;
_springBack.Frequency = _hzBack;
_springBack.DampingRatio = _zeta;

_springFront = new LineJoint(_car, _wheelFront, _wheelFront.Position, axis);
_springFront.MotorSpeed = 10.0f;
_springFront.MaxMotorTorque = 10.0f;
_springFront.MotorEnabled = true;
_springFront.Frequency = _hzFront;
_springFront.DampingRatio = _zeta;



Mar 10, 2012 at 2:19 PM

         Without a test bed it's hard to know exactly what your problem may be. you can try increasing the frequency on the front and rear springs and see if that stabalizes things.

Mar 10, 2012 at 3:10 PM

Thanks for the suggestion. I tried increasing the frequency, but it does not seem to change much. And if it did help, I wouldn't have a clue about why that helped. I suspect that my understanding of the axis is also a little off. Can you explain how it works?

Mar 10, 2012 at 3:30 PM

Well I'm to sure were your understanding is. But in short Line Joints are the same as Prismatic Joints with the rotation restriction removed. In essence a tire can slide along and axis ie the shocks when it's rotating.The spring of the shocks can be modelled by creating friction using the moto variables. Hope this makes things a bit clearer. If you can put together a test I'd be able to help you further.

Mar 10, 2012 at 4:49 PM

Well, I don't really know how to put up a test that I can share with you, but if you look at the CarTest in the Testbed samples and change the axis from {0, 1.0f} to {0, 1.6f} or higher then the same problem occurs.

Mar 11, 2012 at 2:25 AM

Perhaps you could try scaling things down a bit - your car is 125m long x 32m wide. With density of 2 it weighs about 8t. Or in alternative scale the axis.