Redirecting you to bearmacstudios.com.... BearMac Studios: Sprint Script

Pages

Thursday, January 26, 2012

Sprint Script

Just a little script that makes the default FPS controller in unity have a sprint function.

//Sprinting with the default fpscontroller in Unity 3.0

var sprintSpeed : float = 15;
var defaultSpeed : float = 10;

//sets default run speed
function Start () {
 GetComponent(CharacterMotor).movement.maxForwardSpeed = defaultSpeed;
 }
//When the sprint button is pressed, change speed to sprint
function Update () {
if (Input.GetButtonDown("Sprint")){
  GetComponent(CharacterMotor).movement.maxForwardSpeed = sprintSpeed;
  }
//When the sprint button is let up, change back to walk speed
if (Input.GetButtonUp("Sprint")){
 GetComponent(CharacterMotor).movement.maxForwardSpeed = defaultSpeed;
}
}

1 comment: