Last active
December 15, 2015 15:39
-
-
Save benmcnelly/5283336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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