Implementing a wheeled character controller

Posted by Lazlo on Game Development See other posts from Game Development or by Lazlo
Published on 2012-09-13T20:27:29Z Indexed on 2012/09/13 21:50 UTC
Read the original article Hit count: 287

I'm trying to implement Boxycraft's character controller in XNA (with Farseer), as Bryan Dysmas did (minus the jumping part, yet).

My current implementation seems to sometimes glitch in between two parallel planes, and fails to climb 45 degree slopes. (YouTube videos in links, plane glitch is subtle).

How can I fix it? From the textual description, I seem to be doing it right.

Here is my implementation (it seems like a huge wall of text, but it's easy to read. I wish I could simplify and isolate the problem more, but I can't):

public Body TorsoBody { get; private set; }
public PolygonShape TorsoShape { get; private set; }
public Body LegsBody { get; private set; }
public Shape LegsShape { get; private set; }
public RevoluteJoint Hips { get; private set; }
public FixedAngleJoint FixedAngleJoint { get; private set; }
public AngleJoint AngleJoint { get; private set; }

...

this.TorsoBody = BodyFactory.CreateRectangle(this.World, 1, 1.5f, 1);
this.TorsoShape = new PolygonShape(1);
this.TorsoShape.SetAsBox(0.5f, 0.75f);
this.TorsoBody.CreateFixture(this.TorsoShape);
this.TorsoBody.IsStatic = false;

this.LegsBody = BodyFactory.CreateCircle(this.World, 0.5f, 1);
this.LegsShape = new CircleShape(0.5f, 1);
this.LegsBody.CreateFixture(this.LegsShape);
this.LegsBody.Position -= 0.75f * Vector2.UnitY;
this.LegsBody.IsStatic = false;

this.Hips = JointFactory.CreateRevoluteJoint(this.TorsoBody, this.LegsBody, Vector2.Zero);
this.Hips.MotorEnabled = true;
this.AngleJoint = new AngleJoint(this.TorsoBody, this.LegsBody);
this.FixedAngleJoint = new FixedAngleJoint(this.TorsoBody);

this.Hips.MaxMotorTorque = float.PositiveInfinity;
this.World.AddJoint(this.Hips);
this.World.AddJoint(this.AngleJoint);
this.World.AddJoint(this.FixedAngleJoint);

...

public void Move(float m) // -1, 0, +1
{
    this.Hips.MotorSpeed = 0.5f * m;
}

© Game Development or respective owner

Related posts about XNA

Related posts about physics