I'm trying to implement Boxycraft's character controller in XNA (with Velcro Physics), 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.

(Note: my coordinates system is top for positive Y).

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.IsStatic = false;

this.LegsBody = BodyFactory.CreateCircle(this.World, 0.5f, 1);
this.LegsShape = new CircleShape(0.5f, 1);
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;


public void Move(float m) // -1, 0, +1
    this.Hips.MotorSpeed = 0.5f * m;
  • \$\begingroup\$ For the slope I think it may be slipping set the friction of the wheel body to infinity. Box2D spheres are bad for terraria like games due to the single point of contact. I know of no other way to fix the parallel planes issue other than not having parallel planes. \$\endgroup\$ Commented Sep 13, 2012 at 21:00
  • \$\begingroup\$ Also I suggest using a polygon that tapers off towards your characters feet. More intuitive physical characteristics imo and things like the parallel plane issue are less of a problem thanks larger contact area. \$\endgroup\$ Commented Sep 13, 2012 at 21:03
  • \$\begingroup\$ I tried making the friction higher - it helped the realism (it's much less jaggy), but I still can't climb. I also tried removing the angle joint - still can't climb. Could you illustrate your second suggestion? \$\endgroup\$
    – Lazlo
    Commented Sep 13, 2012 at 21:15
  • \$\begingroup\$ Higher or infinity? And I'll post some code after work about the second suggestion. \$\endgroup\$ Commented Sep 13, 2012 at 21:22
  • \$\begingroup\$ Infinity crashed the engine. \$\endgroup\$
    – Lazlo
    Commented Sep 13, 2012 at 21:29

1 Answer 1


I personally don't like the wheeled approach. I use three edges. An infinite inertia prevents it from being rotated (float.MaxValue) and a restitution of 0 prevents if from bouncing. Also the edges are friction-less I set the velocity values in the code. People find realistic physics counter intuitive because they have been trained on what to expect by games like Mario, SMB, and such.

Out side of being more intuitive I also find it easier to work with artistically. I have a wall pushing animation that is triggered if either outside edge is getting hit. I have a sliding animation for the same condition as ling as the middle edge isn't hitting anything.

Also I found most people picked up on the movement a lot faster when I lerped to a max value and then clamped it there. I also lerp back down to 0 speed except when the player is in the air I don't use friction to slow the player. This prevented people from complaining the character was "slidy". Air behavior and ground behavior is the same except air movement speed is capped to the speed when the jump occurred and there is no lerp back to 0 horizontal speed.

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .