Ejemplo n.º 1
0
    void LateUpdate()
    {
        transform.rotation = target.rotation * Quaternion.AngleAxis(90, target.right);

        Transform t = target;

        if (mario.StateCompare(MarioMachine.MarioStates.Climb))
        {
            t = CenterOfGravity;
        }

        transform.position = t.position + (controller.up * controller.radius);

        projector.farClipPlane = controller.currentGround.Hit.distance + controller.radius * 6;
    }
    void LateUpdate()
    {
        var height              = Mathf.Lerp(MinHeight, MaxHeight, currentCameraPosition);
        var maxHeight           = Mathf.Lerp(MinMaximumJumpHeight, MaxMaximumJumpHeight, currentCameraPosition);
        var maxHeightAdjustment = Mathf.Lerp(MinMaxHeightAdjustment, MaxMaxHeightAdjustment, currentCameraPosition);
        var distance            = Mathf.Lerp(MinDistance, MaxDistance, currentCameraPosition);
        var angle  = Mathf.Lerp(MinAngle, MaxAngle, currentCameraPosition);
        var weight = Mathf.Lerp(MinDampWeight, MaxDampWeight, currentCameraPosition);

        Vector3 targetPoint = target.position;

        if (mario.StateCompare(MarioMachine.MarioStates.Hang) || mario.StateCompare(MarioMachine.MarioStates.Climb))
        {
            targetPoint = mario.ClimbTarget();

            if (!planarDamping)
            {
                SetPlanarDamping(true);
            }
        }
        else
        {
            if (planarDamping)
            {
                SetPlanarDamping(false);
            }
        }

        if (!mario.Airborn())
        {
            liftoffPoint = targetPoint;

            verticalPosition = Vector3.SmoothDamp(verticalPosition, Math3d.ProjectPointOnLine(Vector3.zero, controller.up, targetPoint + height * controller.up), ref currentDampVelocity, 0.2f);

            currentRotationVertical = Mathf.SmoothDamp(currentRotationVertical, 0, ref currentRotationVelocity, 0.2f);
        }
        else
        {
            Vector3 groundPosition = Math3d.ProjectPointOnLine(Vector3.zero, controller.up, liftoffPoint);
            Vector3 airPosition    = Math3d.ProjectPointOnLine(Vector3.zero, controller.up, targetPoint);

            float jumpHeight = Vector3.Distance(groundPosition, airPosition);

            var dropRotation = Mathf.Lerp(MinDropRotation, MaxDropRotation, Mathf.InverseLerp(MinDropDistance, MaxDropDistance, jumpHeight));

            if (SuperMath.PointAbovePlane(controller.up, liftoffPoint, targetPoint))
            {
                float extraJumpHeight = 0;

                if (jumpHeight > maxHeight)
                {
                    extraJumpHeight = Mathf.Clamp(jumpHeight - maxHeight, 0, maxHeightAdjustment);
                }

                verticalPosition = Vector3.SmoothDamp(verticalPosition, groundPosition + controller.up * ((jumpHeight * weight) + height + extraJumpHeight), ref currentDampVelocity, 0.1f);
            }
            else if (SuperMath.PointAbovePlane(controller.up, liftoffPoint - controller.up * MinDropDistance, targetPoint))
            {
                verticalPosition = Vector3.SmoothDamp(verticalPosition, Math3d.ProjectPointOnLine(Vector3.zero, controller.up, targetPoint + height * controller.up), ref currentDampVelocity, 0.1f);
            }
            else
            {
                currentRotationVertical = Mathf.SmoothDamp(currentRotationVertical, dropRotation, ref currentRotationVelocity, 0.5f);
            }
        }

        Vector3 direction = Math3d.ProjectVectorOnPlane(controller.up, (targetPoint - transform.position).normalized);

        float angleAdjustment = Vector3.Angle(direction, Math3d.ProjectVectorOnPlane(controller.up, transform.forward));

        if (!AutoTrack)
        {
            angleAdjustment = 0;
        }

        angleAdjustment = SuperMath.PointAbovePlane(transform.right, transform.position, targetPoint) ? angleAdjustment : -angleAdjustment;

        currentRotationHorizontal = SuperMath.ClampAngle(currentRotationHorizontal - input.Current.CameraInput.x * XSensitivity + angleAdjustment);

        transform.rotation = Quaternion.AngleAxis(currentRotationHorizontal, controller.up);

        currentCameraPosition = Mathf.Clamp(currentCameraPosition - input.Current.CameraInput.y * YSensitivity, 0, 1);

        if (planarDamping)
        {
            planarPosition = Vector3.SmoothDamp(planarPosition, Math3d.ProjectPointOnPlane(controller.up, Vector3.zero, targetPoint), ref planarDampVelocity, 0.2f);
        }
        else
        {
            planarPosition = Math3d.ProjectPointOnPlane(controller.up, Vector3.zero, targetPoint);
        }

        transform.position = planarPosition + verticalPosition - transform.forward * distance + cameraShakePosition + constantShakePosition;

        transform.rotation = Quaternion.AngleAxis(angle + currentRotationVertical, transform.right) * transform.rotation;

        currentShakeMagnitude = 0;
    }