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. Dismiss Notice

[C#] How to go about rotating a 2D object

Discussion in 'Scripting' started by pKallv, May 21, 2014.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,122
    I have a number of object with different rotation position and at a given time I want all objects to restore rotation to 0. I want that "return-rotation" to be animated meaning it should not happen instantly.

    I am currently testing on a single object, tag = SK, but do not understand how to achieve this so it looks smooth.

    I am currently testing on this code, not placed in Update():

    Code (csharp):
    1. float speed2 = 5;
    2. float zRotation = 90.0f; // Just a test number to try to understand
    3. dummyGameObject = GameObject.FindWithTag("SK");
    4. dummyGameObject.transform.eulerAngles = new Vector3(dummyGameObject.transform.eulerAngles.x, dummyGameObject.transform.eulerAngles.y, zRotation * speed2 * Time.deltaTime);
    5.  
    I would appreciate any help on this topic as i do not really understand this fully.
     
  2. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,122
    I finally solved the basic problem with this piece of code:

    Code (csharp):
    1.  
    2. if (isRotate) {
    3.     dummyGameObject.transform.Rotate(0, 0, myRotationSpeed * Time.deltaTime * posOrNeg);       
    4. }