- Home /
Smooth rotation problem
I saw many expanaitons about smooth rotation but i can't figure out how it works in my project. I want to rotate a wheel by a constant angle from the current position on the X axis if a button is pushed.
This is the current state:
using UnityEngine;
using System.Collections;
public class rotor1 : MonoBehaviour {
public float rotate_angle = 360f/26f;
public int turn_on = 1;
public int i = 0;
public int j = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if((Input.GetButtonDown("A") || Input.GetButtonDown("S") || Input.GetButtonDown("B") || Input.GetButtonDown("C") || Input.GetButtonDown("D") || Input.GetButtonDown("E3") || Input.GetButtonDown("F") || Input.GetButtonDown("G") || Input.GetButtonDown("H") || Input.GetButtonDown("I8") || Input.GetButtonDown("J") || Input.GetButtonDown("K") || Input.GetButtonDown("L") || Input.GetButtonDown("M") || Input.GetButtonDown("N") || Input.GetButtonDown("O9") || Input.GetButtonDown("P0") || Input.GetButtonDown("Q1") || Input.GetButtonDown("R4") || Input.GetButtonDown("T5") || Input.GetButtonDown("U7") || Input.GetButtonDown("V") || Input.GetButtonDown("W2") || Input.GetButtonDown("X") || Input.GetButtonDown("Y") || Input.GetButtonDown("Z6")))
{
i++;
if (i % turn_on == 0 && i != 1){
transform.Rotate(rotate_angle, 0, 0);
j++;
Debug.Log(j + "/26 fordulat");
if ( j % 26 == 0){
Debug.Log("Teljes fordulat");
}
//light.intensity = 3;
}
}
}
}
Answer by Ray-Pendergraph · Jun 11, 2012 at 12:21 PM
¥our angle is too large for a multi frame operation. You either need to lerp from one rotation to another or decrease the rotate_angle greatly. Update gets called many times a second. Your code is if you want to rotate a known angle all at one time. This rotates a wheel very slowly around the Y axis:
void Update () {
transform.Rotate(0,Time.deltaTime * 5,0);
}
Your code sets rotate_angle to roughly 14 degrees so multiply that times 30 frames a second and that's about 415 degrees of rotation a second. Time.deltaTime * 5 is less than 1.