- Home /
This post has been wikified, any user with enough reputation can edit it.
Can someone help me add running to my script?
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;
}
Comment
Answer by roojerry · May 16, 2013 at 08:37 PM
I would use Input.GetKeyDown and modify your MoveSpeed variable (i.e. MoveSpeed *= 1.5f).
Then on Input.GetKeyUp, I would set MoveSpeed back to default
Your answer
Follow this Question
Related Questions
Maintaining Run on direction change (double tap using GetAxis) 0 Answers
FPS movements. 0 Answers
What's wrong with my sprinting logic? 1 Answer
Animations Can't Be Execute 0 Answers
Sprinting Script Issue 1 Answer