Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update() {
- //Set Inputs for easier access in the script
- leftStickInput = new Vector3((Input.GetAxisRaw("Horizontal")), 0f, (Input.GetAxisRaw("Vertical")));
- rightStickInput = new Vector3((Input.GetAxisRaw("RS Horizontal")), 0f, (Input.GetAxisRaw("RS Vertical")));
- if (playerController.isGrounded) {
- moveDirection.y = 0.0f;
- }
- }
- void LateUpdate() {
- //Final Move Command
- moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale) * Time.deltaTime; //Gravity
- playerController.Move((new Vector3(GetMoveDirection().x, moveDirection.y, GetMoveDirection().z)) * GetMoveSpeed() * Time.deltaTime);
- }
- float GetMoveSpeed() {
- if (leftStickInput.sqrMagnitude > 0.03f && playerController.isGrounded) {
- outputSpeed = Mathf.Lerp(outputSpeed, moveSpeed, (7f * Time.deltaTime));
- stoppedOnGround = false;
- } else if (leftStickInput.sqrMagnitude < 0.03f && playerController.isGrounded) {
- outputSpeed = Mathf.Lerp(outputSpeed, 0, (7f * Time.deltaTime));
- stoppedOnGround = true;
- } else if (!playerController.isGrounded) {
- outputSpeed = Mathf.Lerp(outputSpeed, moveSpeed, (7f * Time.deltaTime));
- }
- return outputSpeed;
- }
- Vector3 GetMoveDirection() {
- if (leftStickInput.sqrMagnitude > 0.03f && playerController.isGrounded) {
- finalMovement = leftStickInput;
- heldMovement = leftStickInput;
- } else if (leftStickInput.sqrMagnitude < 0.03f && playerController.isGrounded) {
- finalMovement = heldMovement;
- } else if (leftStickInput.sqrMagnitude > 0.03f && !playerController.isGrounded) {
- finalMovement = Vector3.Lerp(finalMovement, leftStickInput / 2, 1f * Time.deltaTime);
- }
- return finalMovement;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement