Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Rotating Object on Y Axis with Finger and applying Torque/Inertia

Discussion in 'Physics' started by g0tNoodles, Jul 11, 2018.

  1. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    191
    Hello,

    I am trying to make a spinning wheel type game where the player can use their finger to rotate the wheel. The rotation follows the players movement in a full 360 degrees but this is where I start to have issues - it is based on the screen width/height which causes problems on different devices I am assuming.

    The ideal gameplay would be:

    Players touches the wheel,
    Wheel rotates to follow finger,
    Upon letting go, the wheel continues to spin with inertia, eventually coming to a stop

    I have tried it on 3 different devices and get 3 very different results. Can anyone point me in the right direction to produce what is probably a much simpler implementation of the desired interaction?

    This is what I currently have for following the finger:

    Code (CSharp):
    1. if (touch.position.x > Screen.width / 2)
    2. {
    3.      // Right
    4.      if (f_lastX < Input.GetAxis("Mouse Y"))
    5.      {
    6.         i_direction = 1;
    7.         transform.Rotate(Vector3.down, spinSpeed * Time.deltaTime);
    8.      }
    9.      if (f_lastX > Input.GetAxis("Mouse Y"))
    10.      {
    11.         i_direction = -1;
    12.         transform.Rotate(Vector3.down, -spinSpeed * Time.deltaTime);
    13.       }
    14. }
    15. else if (touch.position.x < Screen.width / 2)
    16. {
    17.      // Left
    18.      if (f_lastX < Input.GetAxis("Mouse Y"))
    19.      {
    20.          i_direction = -1;
    21.          transform.Rotate(Vector3.down, -spinSpeed * Time.deltaTime);
    22.       }
    23.       if (f_lastX > Input.GetAxis("Mouse Y"))
    24.       {
    25.          i_direction = 1;
    26.          transform.Rotate(Vector3.down, spinSpeed * Time.deltaTime);
    27.        }
    28. }
    29.        f_lastX = -pointerY;
    30. }
    Thanks!