void handleMovement(float msMod = 1.0f, bool canJump = true, bool canTurnAround = true) { if (heldObject != null) { msMod *= 0.5f; canJump = false; } Vector2 input = new Vector2(0, 0); if (!(state == State.WaitMoveable && isGrounded())) { input = new Vector2(AtlasInputManager.getAxisState("Dpad").x, AtlasInputManager.getAxisState("Dpad").y); } if (isGrounded() || coyoteTime > 0) { if (AtlasInputManager.getKeyPressed("Jump") && canJump) { firstJump(); } if (AtlasInputManager.getKeyPressed("Broom")) { triggerBroomStart(); } if (isGrounded()) { if (!canBroom && state == State.Movement) { canBroom = true; } canDoubleJump = true; resourceManager.Instance.restoreMana(); } } else { if (canBroom && AtlasInputManager.getKeyPressed("Broom")) { if (wallRiding) { flipHorizontal(); triggerBroomStart(fastBroom, facing); } else { triggerBroomStart(fastBroom); } return; } if (hasWallJump && wallRiding && AtlasInputManager.getKeyPressed("Jump") && resourceManager.Instance.getPlayerMana() >= 2) { state = State.WallJumpInit; return; } if (hasDoubleJump && AtlasInputManager.getKeyPressed("Jump") && canJump && canDoubleJump && resourceManager.Instance.getPlayerMana() >= 1) { doubleJump(); } } float currentMoveSpeed = moveSpeed; if (isCrouching()) { currentMoveSpeed = 1.5f; } float targetVelocityX = input.x * currentMoveSpeed * msMod; anim.SetBool("isRunning", isGrounded() && (targetVelocityX != 0)); anim.SetBool("isJumping", !isGrounded() && (velocity.y > 0) && canDoubleJump); anim.SetBool("isFalling", !isGrounded() && (velocity.y < -0.5f) && !controller.collisions.descendingSlope && !heldObject); anim.SetBool("wallSlide", wallRiding); if (wallRiding) { deformer.RemoveDeform("jump"); deformer.RemoveDeform("fastfall"); } if (canTurnAround) { setFacing(velocity.x); } velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? groundAccelerationTime : airAccelerationTime); velocity.y += gravity * Time.deltaTime * ((wallRiding && velocity.y <= 0) ? 0.5f : 1.0f); if (wallRiding && velocity.y < maxWallSlideVel) { velocity.y = maxWallSlideVel; } float termVel; if (fastFalling) { if (AtlasInputManager.getAxisState("Dpad").y >= 0 || isGrounded() || velocity.y > 0) { fastFalling = false; } termVel = fastFallVel; velocity.y += gravity * Time.deltaTime; } else { termVel = maxFallVel; deformer.RemoveDeform("fastfall"); if (AtlasInputManager.getKeyPressed("Down") && !isGrounded() && (velocity.y <= 0.5f || !AtlasInputManager.getKey("Jump"))) { fastFalling = true; deformer.startDeform(new Vector3(0.85f, 1.4f, 1.0f), 0.2f, -1.0f, -1.0f, "fastfall", true); } } if (velocity.y < termVel) { velocity.y = termVel; } if (velocity.y <= 0 && controller.isSafePosition()) { lastSafePosition = transform.position; } }