using UnityEngine;
using System.Collections;

public class Canoo1_delayed : MonoBehaviour {
	
	private int frame = 0;
	private bool started = false;
	public GameObject canoo;
	private Canoo1 present;
	private InputData history;
	private float forwardMultiplier = -1.0f;
	
	// Use this for initialization
	void Start () {
		present = canoo.GetComponent("Canoo1") as Canoo1;
	}
	
	public void init(){
		started = true;
	}
	
	// Update is called once per frame
	void Update () {
		if(started)
		{	
		
		history = present.getHistory(frame);
			
		gameObject.rigidbody.AddForce(new Vector3(-history.left + history.right, -Mathf.Abs(history.forward) * forwardMultiplier, 0));
			
		gameObject.rigidbody.AddRelativeTorque(new Vector3(0.0f, 0.0f, history.torqueLeft - history.torqueRight));

		frame++;
		if(frame > 49)
			frame = 0;
		}
	
	}
}
