Jump to content

  • Log In with Google      Sign In   
  • Create Account


How do you approach 2D platformers in Unity?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 AniMerrill   Members   -  Reputation: 203

Like
0Likes
Like

Posted 01 April 2014 - 07:42 PM

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


AniMerrill, a.k.a. Ethan Merrill


Sponsor:

#2 UltimateWalrus   Members   -  Reputation: 190

Like
0Likes
Like

Posted 17 April 2014 - 05:35 PM

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 );
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS