Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Looking for 2D Platformer like Mario example

Discussion in 'General Discussion' started by stuartb, Dec 25, 2014.

  1. stuartb

    stuartb

    Joined:
    Aug 19, 2013
    Posts:
    21
    Merry Christmas!

    I've recently been trying to create a 2D Platform game pretty much like Super Mario. I'm having difficulty with the movement and stomping on enemies so I've been looking for a good example project to learn from.

    There are a few of 2D Platformers on the asset store but they all use guns to fight enemies and not all use the new 2D features of Unity.

    Does anyone have or know of somewhere to find a good example project of something like Super Mario where you run around, jump on platforms and stomp on enemies? Preferably using the 2D Unity features. Cheers :)
     
  2. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    Google "2d mario tutorial" the first 3 links are unity. Dont know if the third one uses it. The first two dont since they are old but quite detailed and could prove some challenge in conversion.
     
  3. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Out of curiosity do you mean like in Super Mario Bros were you have to hold down the button to jump high?
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Try the Learn page. it's got a platformer with guns using unity's new 2D features, by unity. If you can't work out stomping, perhaps make a separate post focussed on how far you've got so far.
     
  5. thxfoo

    thxfoo

    Joined:
    Apr 4, 2014
    Posts:
    515
    Early mario had a very simple logic: if velocity of mario is downward and he touches an enemy, the enemy dies. Later titles probably extend that to mario also being in the air.

    There are some youtube videos about mario playing AIs that show that: the AIs learn to abuse that to kill enemies without actually jumping on the enemy.
     
    Not_Sure likes this.
  6. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    Wait, how can you velocity be downwards and you not be in the air? Maybe I'm missing something here. The only way I see it is on falling/moving platforms, in the case of you hitting the side of the enemy instead of the head. Is that what you are referring too?
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The Other Brothers head stomp code simply checks if vel.y<0 and hit.y> half char height.
    Basically, if it's moving down and it collided above the enemy from halfway up then it's a valid stomp. The reason for the halfway check is so that coming down, you won't stomp something if you brush your face against it for example and its on a platform higher than you.
     
    Not_Sure likes this.
  8. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    Oh, man did I nuke this. I always thought there was a trigger that extended past the rigid body.
     
  9. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Same here, very easy to over complicate things.
     
    BrandyStarbrite likes this.
  10. stuartb

    stuartb

    Joined:
    Aug 19, 2013
    Posts:
    21
    That sounds great thanks! So much simpler than what I was trying to do haha!
     
  11. thxfoo

    thxfoo

    Joined:
    Apr 4, 2014
    Posts:
    515
    Later titles have parts where the ground is not flat. So you could be walking down a hill.
     
  12. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    Thanks, I knew I was missing something, duh. I've played pretty much all of them up to the Gamecube so I should have known that.