using UnityEngine;

public class SteerGuide : MonoBehaviour {

    private Engine engine;
    private SteeringWheel steering;
    private Vector3 origin;

	void Start ()
    {
        origin = transform.localPosition;
        engine = transform.root.GetComponent<Engine>();
        steering = transform.root.GetComponent<SteeringWheel>();	
	}
	
	void Update ()
    {
        float speedscale = 1;
        if(engine.ThrottleFactor > 0)
        {
            speedscale += engine.ThrottleFactor*3f;
        }
        else if (engine.ThrottleFactor < 0)
        {
            speedscale = -1 + engine.ThrottleFactor * 1.5f;
        }
        transform.localScale = new Vector3(1, speedscale, 1);

        transform.localEulerAngles = new Vector3(0, 0, -steering.MaxAngle * steering.SteeringFactor);
      
        transform.localPosition = origin + new Vector3(3*steering.SteeringFactor, 3*engine.ThrottleFactor, 0);
	}
}
