using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
//Variables
private float speed = 30F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public float sprint = 6.0F;
private Vector3 moveDirection = Vector3.zero;
//cancelback disables sprinting backward
private bool bsprint = false;
void Awake() {
bsprint = false;
}
void Update() {
CharacterController controller = GetComponent<CharacterController>();
// is the controller on the ground?
if (controller.isGrounded) {
//Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
//Multiply it by speed.
moveDirection *= speed;
//Jumping
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
//Sprint Speed
if (Input.GetKeyDown (KeyCode.LeftShift))
speed = sprint;
bsprint = true;
//Stop Sprint
if (Input.GetKeyUp (KeyCode.LeftShift))
speed = 30F;
bsprint = false;
//Stop Backward Sprinting
if (bsprint == true)
if (Input.GetKeyDown (KeyCode.S))
speed = 30F;
}
//Applying gravity to the controller
moveDirection.y -= gravity * Time.deltaTime;
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
}
}