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

RevolutionJoint, PinJoint question

Topics: Developer Forum, User Forum
Apr 21, 2008 at 8:02 PM
Hi, im building a platformer game and im trying to make the character from a circle and a rectangle

The circle is like a wheel and the rectangle is acting like the body of the character

Is there a way to make the rectangle aways on top of the circle and not stop the circle movement? (rotation)

i tryed with PinJoint but both circle and rectangle start rotation and with RevolutionJoint they never got one on top of the other

the lest thing i tryed was modifying the position of the rectangle to be on top of the circle but on that case this crash farseer colision on some cases and ignore it on others...

sry bad inglesh...
Apr 21, 2008 at 10:54 PM
I use similar geoms for my player (circle and rectangle), but I do not use torque of the circle.

When I move my player, I just set the linearvelocity of the body like this:

if (input.CurrentKeyboardState.IsKeyDown(Keys.D))
if (OnGround)
body.LinearVelocity = new Vector2(100, body.LinearVelocity.Y);

This moves the whole playerbody. I also call ApplyForces every Update which applys other forces to the player like gravity.

It looks something like this:
public void ApplyForce(Vector2 force)
body.Rotation = 0;

And now look at the reset of the Rotation. This lets my player always stand upwards.
With this method I can use all forces, the player is a body in the physicsSimulator and it will not flip out (like it can when you just add forces or use high torque).

For a platformer like game you should always take care about the bodys Rotation (reset it, so that collisions and firction does not rotate it), LinearVelocity (limit it to a maximum player speed, so that it doesnt matter what forces or collisions hit your player, he will not flip around like an out of control rocket).

For me this works perfect!

Oh, and if you want the player to jump, just add an impulse to it like:

body.ApplyImpulse(new Vector2(0, -28000)); (the impulse value depends on gravity and bodymass....)

Hope this helps.
Apr 21, 2008 at 11:06 PM
im doing almost the same thing but my character is a circle on foot and a rectangle on body i almost fixed it i made a revolutionjoint with the foot and momentofinertia of the body set to infinite then i can spin the foot and walk normally..

but my body still move a little in the way of my movement. Now im trying to make it stop moving

if it dont work i will try to make like ur solution but it would be better if i could keep the circle moving for a better movimentation..

ah im not using torque im just using a force on the side of the circle till i get a fixed velocity

thxs for the replay =]
Apr 25, 2008 at 11:41 AM
You might also look at adding an AngleJoint to the body you don't want rotated. The AngleJoint will keep the body from rotating but not from moving around. Normally it is used in conjunction with an Revolute joint but it doesn't have to be. With this joint, you can also set a "MaxTorue" which would allow the body to rotate a little when hit, but it would then right itself.

Just a thought.