示例#1
0
    void bounce()
    {
        List <PaddleSegmentBounceStats> statBlocks = new List <PaddleSegmentBounceStats> {
            lastBounceThisFrame.PaddleSegment.BounceStats
        };

        if (penultimateBounceThisFrame != null && collisionsWereNextToEachOther())
        {
            statBlocks.Add(penultimateBounceThisFrame.PaddleSegment.BounceStats);
        }

        PaddleSegmentBounceStats bounceStats = PaddleSegmentBounceStats.Average(statBlocks);

        float inheritAngleDirection = MathfExtra.TernarySign(Mover.LineRightEdge.position.x - Mover.LineLeftEdge.position.x); // flip the angle if the mover goes from right to left, or don't inherit any angle if the mover goes up and down
        float inheritSpeedAngle     = Mover.Velocity * bounceStats.InheritSpeedAngleMultiplier * inheritAngleDirection;
        float exitAngleOffPaddle    = Mathf.Clamp(bounceStats.BounceAngle + inheritSpeedAngle, -180, 180);

        Ball    ball        = lastBounceThisFrame.Ball;
        float   speed       = bounceStats.BounceSpeed + Mathf.Abs(Mover.Velocity) * bounceStats.InheritSpeedBounceMultiplier;
        Vector2 newVelocity = speed * angleToVector(exitAngleOffPaddle);

        newVelocity.x += ball.Velocity.x * bounceStats.OriginalXSpeedOfBallRetainedOnBounce;

        ball.Bounce(newVelocity, Vector2Int.up);
    }
示例#2
0
    void manageMoveLag()
    {
        var moveDirection = MathfExtra.TernarySign(Mover.Velocity);

        if (moveDirection != previousMoveDirection)
        {
            previousMoveDirection = moveDirection;

            if (moveDirection != 0)
            {
                visualPositionAtStartOfLag = transform.position;
                MoveLagTransition.FlashFromTo(0, 1);
            }
        }

        Visual.transform.position = Vector3.Lerp(visualPositionAtStartOfLag, transform.position + startingVisualLocalPosition, MoveLagTransition.Value);
    }