Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public float speed = 6.0F;
  2. public float jumpSpeed = 8.0F;
  3. public float gravity = 20.0F;
  4. private Vector3 moveDirection = Vector3.zero;
  5. void Update() {
  6. CharacterController controller = GetComponent<CharacterController>();
  7. if (controller.isGrounded) {
  8. moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  9. moveDirection = transform.TransformDirection(moveDirection);
  10. moveDirection *= speed;
  11. if (Input.GetButton("Jump"))
  12. moveDirection.y = jumpSpeed;
  13.  
  14. }
  15. moveDirection.y -= gravity * Time.deltaTime;
  16. controller.Move(moveDirection * Time.deltaTime);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement