Catagories

Thursday, 3 February 2011

Simple Move Character

var speed : float = 3.0;
var rotateSpeed : float = 3.0;

function Update () {
var controller : CharacterController = GetComponent(CharacterController);

// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

// Move forward / backward
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed : float = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);



if (Input.GetAxis("Vertical") > 0.2)
animation.CrossFade ("WalkForward");
else
animation.CrossFade ("Idle2");

}

Camera Follow Script

Add this script to the Main Camera in your Unity Project:

var target : Transform;
var distance = 3.0;
var height = 3.0;
var damping = 5.0;
var smoothRotation = true;
var rotationDamping = 10.0;

function Update () {
var wantedPosition = target.TransformPoint(0, height, -distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);

if (smoothRotation) {
var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
}

else transform.LookAt (target, target.up);
}


NOW ADD COMMENTS TO SHOW WHAT EACH LINE DOES