Example #1
0
    public void HandleMovement(float delta)
    {
        if (inputHandler.rollFlag || playerManager.isInteracting)
        {
            return;
        }

        moveDirection  = cameraObject.forward * inputHandler.vertical;
        moveDirection += cameraObject.right * inputHandler.horizontal;
        moveDirection.Normalize();
        moveDirection.y = 0f;

        float speed = movementSpeed;

        if (inputHandler.sprintFlag && inputHandler.moveAmount > 0.5f)
        {
            speed = sprintSpeed;
            playerManager.isSprinting = true;
            moveDirection            *= speed;
        }
        else
        {
            if (inputHandler.moveAmount < 0.5f)
            {
                moveDirection *= walkingSpeed;
            }
            else
            {
                moveDirection *= speed;
            }
            playerManager.isSprinting = false;
        }

        Vector3 projectedVelocity = Vector3.ProjectOnPlane(moveDirection, normalVector);

        rigid.velocity = projectedVelocity;

        animHandler.UpdateAnimatorValues(inputHandler.moveAmount, 0f, playerManager.isSprinting);

        if (animHandler.canRotate)
        {
            HandleRotation(delta);
        }
    }