Jump to content
  • Advertisement
Sign in to follow this  

Unity How do you approach 2D platformers in Unity?

This topic is 2007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?



Share this post

Link to post
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 );

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!