Search Unity

Can't Rotate Fast Enough

Discussion in 'Scripting' started by imunirbesye, Jan 16, 2019.

  1. imunirbesye

    imunirbesye

    Joined:
    Oct 27, 2018
    Posts:
    57
    I have a object and I want to rotate it with touch. So I wrote this code:

    Code (CSharp):
    1. if(Input.GetTouch(0).phase == TouchPhase.Moved)
    2.              {
    3.                 if (Input.GetTouch(0).deltaPosition.x > 0)
    4.                 {
    5.                     degrees -= 1f;
    6.  
    7.                     if (gameObject.name == "Platform")
    8.                     {
    9.                         gameObject.transform.eulerAngles = new Vector3(degrees, 90, 90);
    10.                     }
    11.                     else if (gameObject.name == "Engel(Clone)")
    12.                     {
    13.                         gameObject.transform.eulerAngles = new Vector3(0, 0, degrees);
    14.                     }
    15. }
    16. }
    degrees' default value is 90. It is not fast enough. I want to rotate like Helix Jump's does. How can I do that?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Line 5 is the rate of your degree change (one degree per frame) when sliding right.

    Make it larger and it will spin faster.

    Ideally you should use something like 100 degrees per second, and then in your degrees math you would instead say:

    Code (csharp):
    1. degrees += 100.0f * Time.deltaTime;
    (This presupposes that your degrees variable is a float. If it is an integer, the above won't work for all the standard data type reasons.)
     
  3. imunirbesye

    imunirbesye

    Joined:
    Oct 27, 2018
    Posts:
    57
    But I want to rotate 1 degree at a time if not than it does not kok smooth ı dont want that.
     
  4. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    Then your only option is to use it on a device that can run your game with more frames per second...because your object can only rotate 1 degree per frame.

    What i mean by that is that @Kurt-Dekker has the answer you want.
     
  5. imunirbesye

    imunirbesye

    Joined:
    Oct 27, 2018
    Posts:
    57
    Thank you. I did it.