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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Rotating object with touch.

Discussion in 'Scripting' started by Uryathel, Sep 21, 2016.

  1. Uryathel

    Uryathel

    Joined:
    Jul 23, 2016
    Posts:
    35
    I have already script for rotating object with touch but it don't works how i want. I know in what is problem but i can't solve it. How can i "reset" cursor position to 0 on place where i touched? Because when i tap on one place and then on another, cursor does line between these places makes my rotation hmm... strange and fast. But when i hold one place and move finger everything is ok, until i want to tap on another place.
    Sorry for bad english.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Are you rotating a 2d or 3d object? What type of rotation are you doing?
     
  3. Uryathel

    Uryathel

    Joined:
    Jul 23, 2016
    Posts:
    35
    3D
     
  4. Uryathel

    Uryathel

    Joined:
    Jul 23, 2016
    Posts:
    35
    Any Ideas?
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Probably need to show some code, because I don't know how you're doing your rotation. I've done rotation with 3D models and I'm not experiencing your problem.
     
  6. Uryathel

    Uryathel

    Joined:
    Jul 23, 2016
    Posts:
    35
    if (Input.GetMouseButton (0)) {
    transform.Rotate (new Vector3 (Input.GetAxis ("Mouse Y") * 1, Input.GetAxis ("Mouse X") * -1, 0) * Time.deltaTime * rotation_speed, Space.World);
    }

    It works correctly only on pc but on android it instant changes position.
     
  7. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
  9. Uryathel

    Uryathel

    Joined:
    Jul 23, 2016
    Posts:
    35
    It's exactly what i need, but i don't know what to do on start.

    Should i do something like:
    case TouchPhase.Moved:
    transform.Rotate (new Vector3 (touch.position.y, touch.position.x, 0) * Time.deltaTime, Space.World);

    or
    case TouchPhase.Began:
    startRot = new Vector3 (touch.position.y, touch.position.x, 0);

    case TouchPhase.Moved:
    moveRot = moveRot - startRot;
    transform.Rotate (moveRot);

    I don't know if it's bad or i don't know where i should put it in code.

    or
    try something with raycasts