# Unity How do you approach 2D platformers in Unity?

## Recommended Posts

AniMerrill    227

Hello all,

So the last couple of days I've had a lot of success helping a friend port his Flash based platformer over to Unity, where we believe we can get it to run better. However, I kinda feel like I'm cheating the system right now, because I'm using a rigidbody (2d of course, since it's a 2d game) to basically get around having to program my own gravity but I'm not using it for any of the other movement (like for jumping, walking, force when the character punches, etc I just manually change the velocity). This works great for almost everything, but I wanted to add in some special kinds of platforms and environments- like sticky platforms, bouncy pads, slippery ice -and I realize I backed myself into a corner because a lot of these things I could have done with friction and different physics settings... if my rigidbody even cared about it now.

I know I can work around this by just adding a couple more states to my character or something, but I'm just curious... how did some of you do it? How do you achieve these mechanics?

~AniMerrill

##### Share on other sites

Unity doesn't exactly have the best collision detection for traditional, non-physics based games.  If you do want a physics based platformer then you're stuck with Rigidbody, but if you don't want physics well, you're still stuck with Rigidbody if you want Unity to help at all with collision detection.  But there are some things you can do to make it suck less.

What I would do is make the player Rigidbody kinematic so that Unity's physics doesn't move it around beyond pushing it out of obstacles.  Now just move it around manually, and if you need fancier things like walljumps, etc., attach more colliders as triggers.  "Programming your own gravity" is trivial and can be done in a few lines:

public float Gravity;
Vector3 _vel;

void FixedUpdate()
{
_vel.y += Gravity;
transform.Translate( vel );
}


## Create an account

Register a new account

• ### Similar Content

• By Yotingo
This is how Odd Oliver see eclipses.

@gygestudios
gyge.co
@yotingo

• You - the chief doctor of the hospital. Working late into the evening, did not notice the majority of hospital workers went home ... But where you disappeared the night shift is also not known. Hastily taking important documents, go home, but something went wrong as usual ... Can you get out of the hospital alive?

We are looking for every position. From Game designer, to marketer, to programmer, to 3D modeler. Any further questions can be discussed through discord
DISCORD: Gator#5635

• Wind Of Fear is a game where we have to kill different kinds of waves of monsters packing weapons. The main goal is to survive the waves and pump up your own weapons. There is a store where you will buy new weapons, scattered crystals that restore your life are also on the map!

Controls:
WASD - Walking
Shift - Running
Mouse1 - Attack
Space - Jump
ScrolDown - weapon change
T - Deceleration of time
Esc - Exit, pause

• Continuation of the first part of the game, Invention. While you were on the island exploring the underground laboratory, the infection was busy spreading throughout the world. In this episode, you have to go through a city populated by monsters in search of salvation aided by weapons that you will find during your travels. The gloomy atmosphere, music and atmosphere and a crowd of walking meat will keep you on your toes!