Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. var speed : float = 6.0;
  2. var jumpSpeed : float = 6.0;
  3. var gravity : float = 12.0;
  4.  
  5. //This variable is now inheriting the Vector3 info (X,Y,Z) and setting them to 0.
  6. private var moveDirection : Vector3 = Vector3.zero;
  7.  
  8. function MoveAndJump() {
  9.  
  10. var controller : CharacterController = GetComponent(CharacterController);
  11.  
  12. if(controller.isGrounded) {
  13. //moveDirection is inheriting Vector3 info. This now sets the X and Z coords to receive the input set to "Horizontal" and "Vertical"
  14. moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Allows player Input
  15. moveDirection = transform.TransformDirection(moveDirection); //How to move
  16. moveDirection *= speed; //How fast to move
  17.  
  18. if(Input.GetButtonDown("Jump")) {
  19. animation.Play("Jump");
  20. moveDirection.y = jumpSpeed;
  21. }
  22. }
  23.  
  24. //Apply gravity
  25. moveDirection.y -= gravity * Time.deltaTime;
  26.  
  27. //This moves the controller
  28. controller.Move(moveDirection * Time.deltaTime);
  29.  
  30. if(Input.GetButton("Fire1")){
  31. animation.Play("Attack");
  32. }
  33.  
  34. if(Input.GetButton("Vertical")){
  35. animation.Play("Run");
  36. }
  37. }
  38.  
  39. function Update() {
  40. MoveAndJump();
  41. }
  42.  
  43. var speed : float;
  44. var jumpSpeed : float;
  45. var gravity : float;
  46.  
  47. private var moveDirection : Vector3 = Vector3.zero;
  48.  
  49. function MoveJumpAttack() {
  50. var controller : CharacterController = GetComponent(CharacterController);
  51.  
  52. if (controller.isGrounded) {
  53. moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, 0);
  54. moveDirection *= speed;
  55.  
  56. if (moveDirection.sqrMagnitude > 0.01)
  57. transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), 90);
  58. }
  59.  
  60. moveDirection.y -= gravity * Time.deltaTime;
  61. controller.Move(moveDirection * Time.deltaTime);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement