예제 #1
0
    private void Update()
    {
        if (dead)
        {
            return;
        }
        var inputPayload = playerConfig.PlayerInput.GetInput();
        var newVelocity  = new Vector2(0f, body.velocity.y);

        var newAimDirection = inputPayload.Aim;

        if (newAimDirection.x != 0 || newAimDirection.y != 0)
        {
            newAimDirection.Normalize();
            aimDirection = newAimDirection;
            crosshair.transform.localPosition = new Vector3(aimDirection.x * crosshairDistance, aimDirection.y * crosshairDistance, 0);
            _catch.SetAimDirection(aimDirection);
        }

        if (inputPayload.Throw)
        {
            if (item)
            {
                _animController.OnThrow();
                item.Throw(aimDirection * throwForce);
                item            = null;
                _catch.HeldItem = null;
            }
        }

        var grounded = Physics2D.Raycast(legs.position, -legs.up, 0.1f, platformLayerMask);

        if (grounded && inputPayload.Jump)
        {
            // Calculate the velocity required to achieve the target jump height.
            newVelocity.y = Mathf.Sqrt(2 * jumpHeight * Mathf.Abs(Physics2D.gravity.y));
            _animController.OnJump();
        }

        // Update the velocity assignment statements to use our selected
        // acceleration and deceleration values.
        newVelocity.x = speed * inputPayload.MoveHorizontal;
        body.velocity = newVelocity;

        // Set Animation state
        _animController.SetGrounded(grounded);
        _animController.ConfigByVelocity(newVelocity);
    }