Hi all, I’m wanting to rotate a object through x number of degrees ( where x entered by user ) on the Y axis & as the title says at a constant rate.
What happens is the rotation starts off slow but increases as the value of the variable " turn" increases. I know this must have something to do with Time.deltatime but I’m not sure how to get round it.
I know ( well hope ) this is probably quite basic stuff for some of you experienced unity users but this is quite new to me.
Any is help appreciated, thanks.
public class planepilot : MonoBehaviour {
public float speed;
private string speedtext = "10" ;
public int ATCspeed = 10;
public int newSpeed ;
private string headingtext = "0" ;
public int ATCheading = 0;
public int newHeading;
public float turn ;
public bool turncomplete = false ;
void Start () {
Debug.Log ("plane script added to :: " + gameObject.name);
speed = 80.0f;
}
// Update is called once per frame
void Update () {
transform.position += transform.forward * Time.deltaTime * ATCspeed;
if (Input.GetKey (KeyCode.Return)) {
ATCspeed = newSpeed; ATCheading = newHeading ;
}
//***************** changes heading ***************
if ((transform.eulerAngles.y) < ATCheading) { turncomplete = false;
turn = transform.eulerAngles.y; turn = turn + 0.02f ;
transform.Rotate (0.0f, turn* Time.deltaTime, 0.0f); Debug.Log(" eulerangles.y = " + (transform.eulerAngles.y) + ( " :: TURN : " + turn ) +
( " / ATC heading : " + ATCheading ) );
}
if (turncomplete == false) {
if ((transform.eulerAngles.y) > ATCheading ) {
transform.eulerAngles = new Vector3 (0.0f, ATCheading, 0.0f);
turncomplete = true;
}
}
}
The function is not taking an absolute angle, but a rotation angle, so you should have an angle (0.02f ?) multiplied by Time.deltaTime, and not add the current angle to it.
Unless I am a really bad reader of the documentation’s example, which is of cource possible.