Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

the problem is how to turn an object with a swipe on android

Discussion in 'Scripting' started by Aparty_, Dec 13, 2020.

  1. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    I have been unable to find a working way to rotate an object with a swipe for a long time, I have tried many scripts, none of them work
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Have you tried.. google? Searching for "unity rotate with swipe" shows about a gazillion results.
     
  3. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    yes, but nothing working was found
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    What problems are you encountering? The concept is always the same and did not change since touch was introduced. You get the movement of the finger over the screen, calculate the delta position change and apply a rotation on the correct axis based on that. Every video or guide covering this topic should do just about that, in some variation or another.

    The touch class provided by Unity even directly comes with a deltaPosition:
    https://docs.unity3d.com/ScriptReference/Touch.html
    So for a simple touch controlled rotation around the y-axis, while you detect the touch, get the delta, multiply it by some desired speed value, calculate the delta rotation based on that and add it to the current rotation.