Kevin Wang
Kevin Wang

Reputation: 3330

Platformer Physics - XNA Farseer C#

So I have been using Farseer for a platformer with physics, and I started running into some concerns as shown below:

Fig 1

When I want my character to jump, I don't only want to apply an impulse to the character body, but more realistically, the character body should be pushing down on objects below it (1) thus propelling itself upwards (2).

Fig2

The same applies when I want my character to move. When the character moves, it should apply force and push off the objects below it (1), not carry the object with it and thus moving in the opposite direction (2).

Although I will be using skeletal animations for this game, I would like to keep it to be a bounding-box shape. This will be a networked game, and the physics will be handled via the server. I prefer to avoid server stress, so I will keep characters to a bounding box and keep all skeletal animations to the client side.

So here are my questions:

Am I forced to "fake" these forces?

Is it reasonable to duplicate skeletal animations on the server side, and just use capsule bodies for the different bones of each character? Will this be too intense?

The game should be able to support 20-30 people per room over multiple rooms. If it comes to it, I would like to avoid very heavy server stress.

I tried to post this to GameDev, but I don't have the reputation to post images there yet, so I will try to find an answer here first.

Upvotes: 2

Views: 1128

Answers (2)

Nic Foster
Nic Foster

Reputation: 2894

Farseer bodies should keep track of any current collisions, this is how the character knows it is supported by something underneath. I would recommend applying a force to whatever the character is supported by, and if you are going for realism, take into account the mass of both the character and the supported object, and how high the jump is going to be. Whatever is calculated as downward force to be applied to the supporting body should be reversed and also applied to the character.

If you want to try and use Farseer to make this happen, rather than calculate it yourself, you might be able to do this using springs, but otherwise pushing down on the supporting object isn't going to get the player to push upward.

Upvotes: 1

jgallant
jgallant

Reputation: 11273

Instead of applying a force in the direction you want your player to move, apply it in the opposite direction. This will essentially create a collision, and the box will push your character up. If you play around with the body restitution property, you might be able to reach an acceptable "bounciness" that could work for you.

You would need to check if your player is resting on top of a box first, or else your player will just fly downwards.

Upvotes: 2

Related Questions