Skip to content

Instantly share code, notes, and snippets.

@benmcnelly
Last active December 15, 2015 15:39
Show Gist options
  • Select an option

  • Save benmcnelly/5283336 to your computer and use it in GitHub Desktop.

Select an option

Save benmcnelly/5283336 to your computer and use it in GitHub Desktop.
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// WTF grounded, so... recalculate?
// freaking move
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply teh gravitahs
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller dummy thing with the camera
controller.Move(moveDirection * Time.deltaTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment