Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. var speed = 6.0;
  2. var jumpSpeed = 8.0;
  3. var gravity = 20.0;
  4.  
  5. private var moveDirection = Vector3.zero;
  6. private var grounded : boolean = false;
  7.  
  8. function FixedUpdate() {
  9. if (grounded) {
  10. // We are grounded, so recalculate movedirection directly from axes
  11. moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  12. moveDirection = transform.TransformDirection(moveDirection);
  13. moveDirection *= speed;
  14.  
  15. if (Input.GetButton ("Jump")) {
  16. moveDirection.y = jumpSpeed;
  17. }
  18. }
  19.  
  20. // Apply gravity
  21. moveDirection.y -= gravity * Time.deltaTime;
  22.  
  23. // Move the controller
  24. var controller : CharacterController = GetComponent(CharacterController);
  25. var flags = controller.Move(moveDirection * Time.deltaTime);
  26. grounded = (flags & CollisionFlags.CollidedBelow) != 0;
  27. }
  28.  
  29. @script RequireComponent(CharacterController)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement