Code:
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var AirSpeed : float = 0.25;
var FireParticle : GameObject;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
animation.CrossFade("Idle");
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0,Input.GetAxis("Horizontal"),0);
if(Input.GetAxis("Vertical")){
animation.CrossFade("Run");
animation["Run"].speed = Input.GetAxis("Vertical")*3;
}
moveDirection = Vector3(0,0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (controller.isGrounded) {
if (Input.GetKey(KeyCode.Space) && controller.isGrounded) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}