So I’ve got Game manager code
public static string GamePhase = "Planning";
public static float MovementTimer = 2.0f;
private static float MovementCountdown = MovementTimer;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Submit") && GamePhase == "Planning")
{
MovementCountdown = MovementTimer;
GamePhase = "Movement";
Debug.Log ("Phase is now" + GamePhase);
}
if(GamePhase == "Movement")
{
MovementCountdown -= Time.deltaTime;
if (MovementCountdown <= 0.0f)
{
GamePhase = "Planning";
Debug.Log ("Phase is now" + GamePhase);
}
}
}
and unit code
public float Heading = 90.0f;
public float Speed = 1.0f;
void Start () {
}
// Update is called once per frame
void LateUpdate () {
if (GamePhaseManager.GamePhase == "Movement")
{
var x = Time.deltaTime * Heading / GamePhaseManager.MovementTimer;
var z = Time.deltaTime * Speed / GamePhaseManager.MovementTimer;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
Debug.Log ("Ship is moving!");
}
}
}
In theory this should make my ship travel a distance of 1 length while turning 90 degrees over a time period of 2 seconds each time I hit the submit button. However, every time it executes, the angle ends up off by ~.5 degrees, and if I try to do a full circle (4 executions) I end up at position x = 0.1019182, position z =-0.1206948, and rotation y = -1.814. What do I need to change so that the movement ends up more precise (exactly 90 degrees every turn)?