Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

(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.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;
}
share|improve this question
    
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. –  ClassicThunder Sep 13 '12 at 21:00
    
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. –  ClassicThunder Sep 13 '12 at 21:03
    
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? –  Lazlo Sep 13 '12 at 21:15
    
Higher or infinity? And I'll post some code after work about the second suggestion. –  ClassicThunder Sep 13 '12 at 21:22
    
Infinity crashed the engine. –  Lazlo Sep 13 '12 at 21:29
show 4 more comments

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.