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

Revolute Joint rotating at constant speed

Dec 25, 2010 at 11:26 PM

Hi everyone,

I am pretty new to Farseer so sorry if this question has an obvious answer.

I want to create a circle that rotates at a constant speed (does not speed up or slow down). I have just quickly put this code together:

            Fixture ground = FixtureFactory.CreateRectangle(world, 100f, 1f, 1f);
            ground.Body.Position = new Vector2(0f, -10f);
            ground.Body.SleepingAllowed = true;

Fixture rollingPlatform = FixtureFactory.CreateCircle(world, 10f, 1f);
rollingPlatform.CollisionGroup = 1;
rollingPlatform.Body.Position = new Vector2(0f, -18f);
rollingPlatform.Body.BodyType = BodyType.Dynamic;
rollingPlatform.Body.SleepingAllowed = false;
rollingPlatform.Friction = 10f;

RevoluteJoint rollingPlatformJoint = JointFactory.CreateRevoluteJoint(ground.Body, rollingPlatform.Body, Vector2.Zero);
rollingPlatformJoint.MaxMotorTorque = 100.0f;
rollingPlatformJoint.MotorTorque = 100.0f;
rollingPlatformJoint.MotorSpeed = -10f;
rollingPlatformJoint.MotorEnabled = true;


The wheel rotates but initially it is not rotating and slowly speeds up. What should I do to make it rotate at a constant speed?

BR Kim

Dec 26, 2010 at 1:50 AM

If you set the MaxMotorTorque to a higher value it will speed up faster.

Another option is to set Body.BodyType = BodyType.Kinematic, and set the AngularVelocity to how fast you want it to spin. This way it will always be spinning at the same speed no matter what.

Kinematic bodies are like fixed bodies, only you can set the velocity. They arent affected by gravity and dont react to collisions.

Dec 26, 2010 at 1:28 PM

Thank you very much for the tip Robertdood .. The Kinematic body solution works perfectly:

// Create rotating wheel platform

Fixture rollingPlatform = FixtureFactory.CreateCircle(world, 10f, 1f);
rollingPlatform.Body.Position = new Vector2(0f, -16f);
rollingPlatform.Body.BodyType = BodyType.Kinematic;
rollingPlatform.Body.AngularVelocity = 0.1f * Settings.Pi;
rollingPlatform.Body.SleepingAllowed = false;
rollingPlatform.Friction = 10f;

Just one question: You write that kinematic bodies do not react to collisions. I need these wheels to build some rotating platforms so they should react to collisions. To be sure I did not misunderstand I tried out the above code in a test environment and my player character did collide with the spinning wheel. Could you please explain what you meant by "dont react to collisions" since I do not want to find out later on that what I thought worked will not work anyway?

Dec 27, 2010 at 6:34 AM

I meant the kinematic body will never move if something collides with it, only the other body. And the same with static bodies. 

Static bodies and kinematic bodies will never collide with each other either, but all other collision with them will work perfectly.

The only way to move a kinematic or static body is to adjust the velocity or position manually.

Dec 28, 2010 at 2:21 PM

Thank you robert .. Now I understand and it makes perfect sense.