Example #1
0
    private bool FootStrike(out GameObject struckObject)
    {
        struckObject = null;

        float radius = controller.radius;

        Vector3 o = controller.OffsetPosition(controller.feet.Offset);

        Collider[] colliders = Physics.OverlapSphere(o, radius, EnemyLayerMask);

        foreach (var col in colliders)
        {
            var machine = col.gameObject.GetComponent <GoombaMachine>();

            if (machine != null)
            {
                if (!machine.Alive)
                {
                    continue;
                }
            }

            Vector3 closestPoint = SuperCollider.ClosestPointOnSurface(col, o, radius);

            if (SuperMath.PointAbovePlane(controller.down, o, closestPoint))
            {
                struckObject = col.gameObject;
                return(true);
            }
        }

        return(false);
    }
Example #2
0
    void Spawned_Update()
    {
        Ball.Rotate(new Vector3(RotationSpeed * Time.deltaTime, 0, 0), Space.Self);

        transform.position += moveDirection * Time.deltaTime;

        RaycastHit hit;

        if (TouchingGround(out hit))
        {
            moveDirection.y = 0;

            if (hit.distance < radius)
            {
                ClampToGround();
            }
        }
        else
        {
            moveDirection.y -= Gravity * Time.deltaTime;
        }

        if (!SuperMath.PointAbovePlane(transform.forward, transform.position, spawnTarget))
        {
            currentState = RollingBallStates.Pathing;
        }
    }
Example #3
0
    public override bool StandingOn(Vector3 position)
    {
        lastTiltTime = Time.time;

        int direction = SuperMath.PointAbovePlane(tiltPlane, Bridge.position, position) ? 1 : -1;

        if (Mathf.Abs(currentRotation) < MaxTilt - TiltSlowBarrier || direction != Mathf.Sign(currentRotation))
        {
            currentSpeed = Mathf.MoveTowards(currentSpeed, TiltSpeed * direction, TiltAcceleration * Time.deltaTime);
        }

        return(false);
    }
    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;
    }