Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. 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!