Advertisement
Guest User

Untitled

a guest
Aug 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1.     void Update() {
  2.         //Set Inputs for easier access in the script
  3.         leftStickInput = new Vector3((Input.GetAxisRaw("Horizontal")), 0f, (Input.GetAxisRaw("Vertical")));
  4.         rightStickInput = new Vector3((Input.GetAxisRaw("RS Horizontal")), 0f, (Input.GetAxisRaw("RS Vertical")));
  5.  
  6.         if (playerController.isGrounded) {
  7.             moveDirection.y = 0.0f;
  8.         }
  9.     }
  10.    
  11.     void LateUpdate() {
  12.         //Final Move Command      
  13.         moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale) * Time.deltaTime; //Gravity
  14.         playerController.Move((new Vector3(GetMoveDirection().x, moveDirection.y, GetMoveDirection().z)) * GetMoveSpeed() * Time.deltaTime);
  15.     }
  16.  
  17.     float GetMoveSpeed() {
  18.         if (leftStickInput.sqrMagnitude > 0.03f && playerController.isGrounded) {
  19.             outputSpeed = Mathf.Lerp(outputSpeed, moveSpeed, (7f * Time.deltaTime));
  20.             stoppedOnGround = false;
  21.         } else if (leftStickInput.sqrMagnitude < 0.03f && playerController.isGrounded) {
  22.             outputSpeed = Mathf.Lerp(outputSpeed, 0, (7f * Time.deltaTime));
  23.             stoppedOnGround = true;
  24.         } else if (!playerController.isGrounded) {
  25.             outputSpeed = Mathf.Lerp(outputSpeed, moveSpeed, (7f * Time.deltaTime));
  26.         }
  27.         return outputSpeed;
  28.     }
  29.  
  30.     Vector3 GetMoveDirection() {
  31.         if (leftStickInput.sqrMagnitude > 0.03f && playerController.isGrounded) {
  32.             finalMovement = leftStickInput;
  33.             heldMovement = leftStickInput;
  34.         } else if (leftStickInput.sqrMagnitude < 0.03f && playerController.isGrounded) {
  35.             finalMovement = heldMovement;
  36.         } else if (leftStickInput.sqrMagnitude > 0.03f && !playerController.isGrounded) {
  37.             finalMovement = Vector3.Lerp(finalMovement, leftStickInput / 2, 1f * Time.deltaTime);
  38.         }
  39.         return finalMovement;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement