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

# Two bodies not centered

 Topics: Developer Forum Wiki Link: [discussion:446776]
Jun 12, 2013 at 11:03 AM
Edited Jun 12, 2013 at 11:03 AM
Hello,

I'm currently learning FPE, and I just got some weird trouble.

# My goal

Basically I would like to have a car whose wheels are legged so that it could jump and wheel.

# My situation

I have a body with two "legs", each leg has one wheel. In this way, I have five bodies:
• A heart (the main body).
• Two little circles jointed to the heart with prismaticjoints.
• Two wheels jointed to the little circles with revolutejoints.
I use motors to make the wheel rotate and the legs translate.

# My problem

On one of the little circles is not centered in the wheel when I use the motor of the prismatic joints. You can check what I mean on this video: http://www.youtube.com/watch?v=1aDTAqNMw8A&feature=em-upload_owner

Would someone have any idea?

# My code

``````        _rod1End = BodyFactory.CreateCircle(_world, 0.1f, 1f, Vector2.Zero);
_rod1End.CollisionGroup = 42;
_rod1End.BodyType = BodyType.Dynamic;

_rod2End = BodyFactory.CreateCircle(_world, 0.1f, 1f, Vector2.Zero);
_rod2End.CollisionGroup = 42;
_rod2End.BodyType = BodyType.Dynamic;

//RodSpot
_jointRod1 = new PrismaticJoint(_heart, _rod2End, new Vector2(0.5f, -1f), new Vector2(0, 0), new Vector2(-1, 1));
_jointRod1.LimitEnabled = true;
_jointRod1.Enabled = true;
_jointRod1.LowerLimit = 1;
_jointRod1.UpperLimit = _sizeRod1 * 3;
_jointRod1.MotorEnabled = true;
_jointRod1.MaxMotorForce = 100;
_jointRod1.MotorSpeed = 0f;

_jointRod2 = new PrismaticJoint(_heart, _rod1End, new Vector2(-0.5f, -1f), new Vector2(0, 0), new Vector2(1, 1));
_jointRod2.LimitEnabled = true;
_jointRod2.Enabled = true;
_jointRod2.LowerLimit = 1;
_jointRod2.UpperLimit = _sizeRod1 * 3;
_jointRod2.MotorEnabled = true;
_jointRod2.MaxMotorForce = 100;
_jointRod2.MotorSpeed = 0f;

// Wheel
_wheel_right = BodyFactory.CreateCircle(_world, 0.5f, 1f, Vector2.Zero);
_wheel_right.BodyType = BodyType.Dynamic;
_wheel_right_tex = _asset.TextureFromShape(_wheel_right.FixtureList[0].Shape, MaterialType.Blank, Color.Gray, 1f);
_wheel_right.CollisionGroup = 42;
_wheel_right.Position = new Vector2(13, 4);

_wheel_left = BodyFactory.CreateCircle(_world, 0.5f, 1f, Vector2.Zero);
_wheel_left.BodyType = BodyType.Dynamic;
_wheel_left_tex = _asset.TextureFromShape(_wheel_left.FixtureList[0].Shape, MaterialType.Blank, Color.LightGray, 1f);
_wheel_left.FixtureList[0].CollisionGroup = 42;
_wheel_left.Position = new Vector2(12, 4);

//Joint test
_spotJoint[1] = new RevoluteJoint(_wheel_right, _rod1End, Vector2.Zero, Vector2.Zero);
_spotJoint[1].Enabled = true;
_spotJoint[1].MotorEnabled = true;
_spotJoint[1].MaxMotorTorque = 10f;
_spotJoint[1].MotorSpeed = 0f;

_spotJoint[0] = new RevoluteJoint(_wheel_left, _rod2End, Vector2.Zero, Vector2.Zero);
_spotJoint[0].Enabled = true;
_spotJoint[0].MotorEnabled = true;
_spotJoint[0].MaxMotorTorque = 10f;
_spotJoint[0].MotorSpeed = 0f;``````
``````          KeyboardState state = Keyboard.GetState();

if (state.IsKeyDown(Keys.W))
{
_jointRod1.MotorSpeed = -20f;
_jointRod2.MotorSpeed = -20f;
}
else if (state.IsKeyDown(Keys.S))
{
_jointRod1.MotorSpeed = 20f;
_jointRod2.MotorSpeed = 20f;
}
else
{
_jointRod1.MotorSpeed = 0f;
_jointRod2.MotorSpeed = 0f;
}``````