Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Movement - Help

Discussion in 'Documentation' started by Ph_Mari3, Oct 14, 2018.

  1. Ph_Mari3

    Ph_Mari3

    Joined:
    Oct 14, 2018
    Posts:
    1
    Hy. I made a snake game, but I have an issue. For example, while moving right if I press left button my snake dies (because of colisions). How could I disable, while moving one direction, the input for the oposite direction? I tried several algorithms but none worked...
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    3,025
    Snake games usually utilize relative steering, which means
    - when the snake is moving to the right, pushing the left button, it will turn and move up
    - when the snake is moving to the left, pushing the left button it will turn and move down
    [...]

    In this case you just do not use the "down button", because it points towards the snake body itself all the time. Otherwise you turn your snake 90 degree to the proper direction.