Hi everyone I am stumped on this running bit. Im trying to add running to my script but I cant seem to make it work. Im trying to run with the left and right shift key. Please help here is the script I have for movement:
public var MoveSpeed :float = 10;
public var jumpSpeed : float = 0;
public var MoveDirection = Vector3.zero;
public var Gravity :float = 45;
public var grounded : boolean = false;
function Update () {
if(grounded){
MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical"));
MoveDirection = transform.TransformDirection(MoveDirection);
MoveDirection *= MoveSpeed;
}
if(grounded){
if(Input.GetKey(KeyCode.Space)){
MoveDirection.y = jumpSpeed;
}
}
MoveDirection.y -= Gravity * Time.deltaTime;
var Controller = GetComponent(CharacterController);
var Flags = Controller.Move(MoveDirection * Time.deltaTime);
grounded = (Flags & CollisionFlags.CollidedBelow) !=0;
}