Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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!