# How do I create a player movement system in Farseer?

My group of students is helping produce a a 2D platformer. We tried making a pixel-based collision system which fell through. Now I am trying this physics engine on for size and see new ways to create and control my player. Like the obvious circle body player:

I was using a different type of player movement system like this XNA video example.

What system would work for a player that needs to be able to jump and move in mid-air (as in the above link), and can run up slopes like the circular body example?

I guess that the circular body can be made to do anything, but would like community input.

• There's no "best". You should better describe why your current solution isn't working for you, and detail the requirements so it's clear what you want. – MichaelHouse Feb 19 '14 at 15:53
• @Byte56 Uh... can we reopen this? I was just about to post a serious answer... (edit: kthx) – Andrew Russell Feb 19 '14 at 15:53
• @AndrewRussell Sure. Though it seems like it's a "list of" type question to me, hopefully your answer can turn that around. – MichaelHouse Feb 19 '14 at 15:56

Please take my answer as "the right way to do this", not necessarily the "good for a student project" way.

Rigid body physics are entirely inappropriate for modeling "walking" behaviour.

Rigid body physics are good for handling things like bouncing and friction. Which are things you want to avoid in a typical platformer. There is no "right shape" that will make a satisfying platformer character on its own.

Basically you need to not be afraid to take matters into your own hands and "override" the physics engine. Rather than working with impulses and forces, like you might for typical physics bodies, you should manually control your player's position and velocity. (Sounds scary, but it's perfectly ok to do.)

I recommend: Before the physics step, set the velocity to an appropriate value using typical platformer movement mechanics. After the physics step, modify the position to correct any unplatformerly behaviours (I find it best to "snap" the player object onto the ground, rather than relying on physics - which can cause the player to "skip" off the ground).

The actual shapes you use are then fairly irrelevant.

Obviously this is a fair bit more work, and you have to be able to deal with the 2D geometry calculations. But the results are markedly better.

Here's how I do it:

My initial attempts used a diamond shape, which is advantageous because it only has one point of contact with the ground to worry about (similar benefits to using a circle, only better). I ignore/cancel collisions with this point in the physics engine (if they're with a ground surface) - because I handle them myself by snapping it to the ground in my "fix-up" step.

(The "weight" effect of the player in that video is done manually too. Without it, this works better with static level geometry.)

More recently I have taken to using a "hovering rectangle". Rather than snapping to the ground, I snap some distance above it. The rectangle body provides collision detection with the walls and ceiling, while the hover behaviour handles the floor.

I'm actually exploring doing away with the rigid body entirely, because I'm working on movements like wall jumping, etc. And, again, rigid bodies aren't well suited for simulating these kind of human movements.

• >Wall jumping. >Human movements. But otherwise, this sounds like really good advice. – Magus Feb 19 '14 at 18:03
• Hah, good point. I was having trouble coming up with a word that meant "moving with limbs, joints, muscles, etc". – Andrew Russell Feb 19 '14 at 23:43
• @Andrew Russell I do thank you again Andrew for the help. I will look into it and try out these ideas. I think that what I am troubled with is that you can create an object, molded it any way you want and still it will work just like you initial attempts. I tried to get more answers by posting Here. My main question I guess is how did you create these randomly shaped object? How you created a diamond player model? Was it a texture? Or was it an in program thing? – Ryan Foy Feb 20 '14 at 13:46
• I answered over in that thread. But basically it's as simple as BodyFactory.CreatePolygon(world, myShape, 1f);. For the player, I just specify the list of vertices in code (there's only four). – Andrew Russell Feb 20 '14 at 15:17
• Collision in a real game is rarely based on the texture. Generally, you make some kind of bounding box for collision, or even one for object collision and one for collision with the environment. – Magus Feb 20 '14 at 15:18