Search Unity

Need a little bit of help with some input logic

Discussion in 'Input System' started by TitoOliveira, Jun 24, 2020.

  1. TitoOliveira

    TitoOliveira

    Joined:
    Aug 4, 2014
    Posts:
    79
    I'm making a sidescroller and there's a particular case on the input system that i don't quite know how to solve.

    By pressing left and right, the player can run in both directions. Regular stuff.
    When the player releases the button, the character does a little slide and then stop, so far so good.

    The thing is, if the player is running right and then quickly changes to left, i want the character to do a special slide changing directions, which is different from the slide to stop.
    It is something similar to the first Prince of Persia, for DOS.

    The logic in my game is similar to a state machine, where i transition into each of these states from other states. I.E. Idle to Accelerate to Run to Slide to Idle again.

    My issue is the following. I'm checking for the input on the update loop. If input.x >0 = right, if input.x < 0 = left.

    This works fine when i'm running and stopping on the same direction, but when i want to slide changing directions theres an issue.If i'm holding right and then change to holding left, so that my character changes direction, there's a few frames where i just released the right button and no input is being held. This triggers the slide to idle state.

    I'm not quite sure how to go about solving this. It feels like i should be looking into a more robust input system, rather than just checking raw values on the update loop.