cjddmut / Unity-2D-Platformer-Controller

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dropped into any scene for immediate support.
MIT License
873 stars 163 forks source link

Moving from walkable slope to wall causes a bounce and stick to wall #43

Open Stevepunk opened 8 years ago

Stevepunk commented 8 years ago

Moving from walkable slope to wall causes a bounce and stick to wall. I doubt this is intended. Each time the player moved against a wall from a slope he bounced up instead of standing still.

He does this even if the minimumSpeedToMoveUpSlipperySlope is set to a large number to stop the player from attempting to climb slopes that he is not able to.

Everything else works great even with procedurally generated meshes/colliders! Awesome work indeed!

Stevepunk commented 8 years ago

To resolve this I added an extra grounded check when encountering a wall: (assuming that if we're grounded and not moving sideways then we also don't want to move vertically either)

    // These mean we can't progress forward. Either a wall or a slope
    if (HasFlag(CollidedSurface.LeftWall) &&
        _velocity.x < 0 &&
        _collidedNormals[DIRECTION_LEFT] == Vector2.right ||
        HasFlag(CollidedSurface.RightWall) &&
        _velocity.x > 0 &&
        _collidedNormals[DIRECTION_RIGHT] == Vector2.left)
    {
        if (IsGrounded())
        {
            velocity = Vector2.zero;
        }
        else
        {
            _velocity.x = 0;
        }   
    }

This resolved the problem for most speeds, but when travelling at fast speeds with a slow computer I found that I had to increase Environment Check Distance from 0.02f to 0.1f.

On even slower computers it may need to be increased more or there may be a more efficient solution..

llafuente commented 8 years ago

I see you have a fork. Can you please commit an example scene and the fix so We can take look.

cjddmut commented 8 years ago

Is this when encountering a wall or a steep slope?

Also, given that this is in FixedUpdate then it shouldn't matter if the computer is fast or slow.

pixellykyle commented 7 years ago

I've also seen this problem and tried the fix from Mr-Sheen a few posts up. It seems to fix the issue in most cases but if the character hits a vertical wall while running up a slope at too high a speed he'll do a little jump/bounce.

All the slopes in my game are 45 degrees, with all other colliders being perfectly horizontal or vertical.