This project has moved and is read-only. For the latest updates, please go here.

2D Sidescroller help

Topics: Developer Forum, User Forum
Apr 9, 2008 at 1:47 AM
Edited Apr 9, 2008 at 7:57 AM
OK, I'm very new to XNA and have only had about 3-4 months of programming in C# so... yeah.

Anyways, I was wondering if Farseer would be good for a 2D Sidescroller game - One where the character can run/jump/shoot/etc...
Or if I should just make my own gravity/collisions...

My experience with this engine so far has been a bit frustrating (although I'm new). My character is an animation that has been thrown onto a Body (rectangle) and put into a Geom (rectangle). And I have key inputs that move the Body's position.

My problem is when I'm running my character (body) off a ledge (static body), or if I'm landing at an angle, the image will sometimes flip or wobble. I realize these are physics of a rectangle, but I'm wondering if there's a way I can store my animations into a Body and detect collision with other Bodies without friction (but I don't want my object moving endlessly when sitting on a static Body), without bouncing (when landing on a static Body), and without rotating (when moving my animation body off a static body).

I still want to use the gravity and collision, just not the collisions reactions (bouncing when landing/etc) and friction.

I've tried removing collision reaction, but that just drops my Body straight through any static Body.
And if I put the friction coefficient to 0, the character (body) just keeps moving either right or left (I understand why, but I can't have friction because it causes the Body to wobble just a bit when it stops).

If anybody has any ideas on how to attack this problem, I'd be very grateful. Thank you!
Apr 9, 2008 at 9:24 AM

to start with your basic problems:

- You could reset the linearRotation of your object each frame. This will let it stay upwards and not rotate on collisions (flip/wobble).
- In any case, ignore the rotation of the geom while rendering the characters image.

But you will find some issues after that... and after solving these you will find new.... etc... So what to do?

A human character is no rectangle. (I bet you already knew that :) ). So basically, if you want to use a rectangle for collision, you should not use the rectangles physics.
In many samples on the internet, a sphere is used for characters physics objects. One reason is, that a rolling circle will not stop at a simple angular landscaperaise. It will roll upwards with a certain speed up to a certain angle.
But even a sphere will not really give you a "correct looking" character movement. I guess there is no "simple" geometric that can be used for a human player.

So what I personally do is: I use a rectangle, but I do NOT use the physics engine for the player. I calculate movement on my own and check collisions with the physicsEngine geoms myself. This gives me any freedom to let my character act like I want and not like the physics engine thinks it should act.

There are too many variables that can let your character "freak out" if you let the physicsengine control him. I have seen geoms that stuck together (you will find many threads about this problem here), I have seen things bouncing off each other even if they shouldn't, I have seen things flying around at very high speeds etc... all this can happen to your character too if he is a physicsEngines object.

So my advice: Control him yourself and check collisions with the geom of the physics engine.