0
\$\begingroup\$

I want a cube to rotate 90 degrees every [Second/Counter should be setable]

Like in this video at 3.47 the spiky cube that turns 90 degrees https://www.youtube.com/watch?v=bxWpsT4lKXU

I have tried to do it but it will not turn 90 degrees smoothly or even 90 degrees, it just turns kind of 90 degrees but I need help I guess.

Here is my script:


public class TurnCubeScript : MonoBehaviour {

public Transform turnCube;

public float turnSpeed;
//SETTING THE COUNTER FOR OBJECT TO TURN
public float setCounter;
public float counter;
//SETTING THE COUNTER TO SETCOUNTER AFTER COUNTER1 = 0
public float setCounter1;
public float counter1;

void Start () 
{
    setCounter = counter + setCounter;
    setCounter1 = counter1 + setCounter1;
}

void Update () 
{
    TurnTheCube();
}

void TurnTheCube()
{

    counter -= 1 * Time.deltaTime;
    if (counter < 1)
    {
        //SOME TRIES... 
        //turnCube.transform.eulerAngles += new Vector3 (0, 0, 90 * Time.deltaTime * turnSpeed);
        //turnCube.Rotate(0, 0, 90 * Time.deltaTime * turnSpeed);
        //turnCube.rotation = Quaternion.Euler(0, 0, rotation);

        counter1 -= 1 * Time.deltaTime;

        //GIVES THE CUBE SOME TIME TO TURN
        if(counter1 < 1)
        {
            counter = setCounter;
            counter1 = setCounter1;
        }
    }
}

}

\$\endgroup\$
1
\$\begingroup\$

If you are looking for a stationary rotating box, you should try using the built in script "auto rotate and translate" and set it to your box. Then, type in the values of how you want it to rotate it.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ its worth noting that AutoRotateAndTranslate is a class member of the StandardAssets.Utility namespace. You will have to import the asset package before it is available. \$\endgroup\$ – Gnemlock Mar 4 '17 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.