using UnityEngine;
using System.Collections;
public class Character Controller : MonoBehaviour {
public float inputDelay = 0.1f;
public float forwardVe1 = 12;
public float rotateVe1 = 100;
Quaternion targetRotation;
Rigidbody rBody;
float forwardInput, turnInput;
public Quaternion TargetRotation
{
get { return targetRotation; }
}
void Start()
{
targetRotation = transform.rotation;
if (GetComponent<Rigidbody>())
rBody = GetComponent<Rigidbody>();
else
Debug.LogError("The character needs a rigidbody.");
forwardInput = turnInput = 0;
}
void GetInput()
{
forwardInput = Input.GetAxis("Vertical");
turnInput = Input.GetAxis ("Horizontal");
}
void Update()
{
GetInput ();
Turn ();
}
void FixedUpdate()
{
Run ();
}
void Run()
{
if (Mathf.Abs (forwardInput) > inputDelay)
{
//move
rBody.velocity = transform.forward * forwardInput * forwardVe1;
}
else
//zero velocity
rBody.velocity = Vector3.zero;
}
void Turn()
{
if (Mathf.Abs (turnInput) > inputDelay)
{
targetRotation = Quaternion.AngleAxis(rotateVe1 * turnInput * Time.deltaTime, Vector3.up)
}
transform.rotation *= targetRotation;
}
}