How do I limit the movement (Touch) of a character to 3 specific points? Unity C #

1

I would like to know how to limit the position of a character on the Y axis in the Up, Mid, Down positions. In the game the character runs while obstacles appear and dragging the finger up, if it is in the "down" position, it moves to the "Mid" position, and if it is in the "Mid", it can go to "up" (dragging to up) or "down" (dragging down) and so on.From already thank you.

    
asked by anonymous 30.03.2016 / 22:39

1 answer

2

You can use the Vector3.MoveTowards function. Then, within Update (), you can use an if statement to get the finger dragging. Dai you use Vector3.MoveTowards to move your object to the desired position. More or less like this

 void Update() {
    if (Swipe pra cima) {
       float step = 3f * Time.deltaTime; //velocidade desejada de movimento.
       Vector3 posiçãoQueVoceQueira = new Vector3(transform.position.x, valorDeterminadoDeY, 0f);
       transform.position = Vector3.MoveTowards(transform.position, posiçãoQueVoceQueira, step);
    }
}

I hope you have helped!

    
09.07.2016 / 21:00