Search Unity

How do you handle slopes?

Discussion in '2D' started by Marscaleb, Sep 9, 2019.

  1. Marscaleb


    Jan 7, 2014
    How do you handle slopes in Unity for a 2D sidescroller?

    I can't figure out a reasonable system.

    With a regular box collider, the player will "stand" on the very corner of their collider, which makes them appear to float just above the slope. Completely undesirable.
    I know some games have simply used collision with rounded bottoms so the collider can slide up slopes. Alternatively one could use very narrow colliders that are much thinner than the character appears.
    But in both of these situations you would have problems when this character reaches a ledge. With a rounded bottom the character will start sliding off of edges once they get half-way past the ledge. With narrow colliders, they would outright fall past the edge once they are past that narrow edge, which puts them at a tug-of-war between looking like they are floating above the slope because their bottom is too wide or falling off an edge too soon because their bottom is narrow. There might not be a happy middle ground depending on the game and artwork.

    The there is the issue of walking seemlessly onto slopes. If a player walks down a slope from its top, under normal circumstances they will have to fall for a frame before they are on the slope, and possibly could fall one frame for each and every step they make downhill, depending on how they are st up.

    So how do you get around this? How do you have slopes set up in a 2D game without revealing some jenky systems?