TO SQUASH: Fucking magnets, how do they work?
This commit is contained in:
@@ -6,14 +6,31 @@ public class FruitBall : BallBase
|
||||
|
||||
private float speedIncreaseTimer = 0.0f;
|
||||
|
||||
private Bounds boardBounds;
|
||||
|
||||
private Collider2D selfCollider;
|
||||
|
||||
private bool hasBoardBounds = false;
|
||||
|
||||
private float magnetBounceDuration = 0.35f;
|
||||
|
||||
private float magnetCenterLeeway = 0.12f;
|
||||
|
||||
private MagnetBounceAxisState xMagnetBounceState;
|
||||
|
||||
private MagnetBounceAxisState yMagnetBounceState;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
animator = GetComponent<Animator>();
|
||||
selfCollider = GetComponent<Collider2D>();
|
||||
speed = new Vector2(Mathf.Sign(Random.Range(-1f, 1f)) * 0.005f,
|
||||
Mathf.Sign(Random.Range(-1f, 1f)) * 0.005f);
|
||||
|
||||
hasBoardBounds = TryCacheGameBoardBounds(out boardBounds);
|
||||
|
||||
audioSource.PlayOneShot(spawnSound);
|
||||
}
|
||||
|
||||
@@ -24,6 +41,35 @@ public class FruitBall : BallBase
|
||||
|
||||
if (stateInfo.IsName("FruitBallMove")) {
|
||||
transform.Translate(speed * speedMultiplier);
|
||||
|
||||
if (affectedByMagnet && hasBoardBounds)
|
||||
{
|
||||
Vector3 currentPosition = transform.position;
|
||||
|
||||
currentPosition.x = ApplyMagnetBounceAxis(
|
||||
currentPosition.x,
|
||||
boardBounds.min.x,
|
||||
boardBounds.max.x,
|
||||
magnetActiveLeftRight,
|
||||
ref xMagnetBounceState,
|
||||
selfCollider != null ? selfCollider.bounds.extents.x : 0.0f,
|
||||
magnetBounceDuration,
|
||||
magnetCenterLeeway
|
||||
);
|
||||
|
||||
currentPosition.y = ApplyMagnetBounceAxis(
|
||||
currentPosition.y,
|
||||
boardBounds.min.y,
|
||||
boardBounds.max.y,
|
||||
magnetActiveTopBottom,
|
||||
ref yMagnetBounceState,
|
||||
selfCollider != null ? selfCollider.bounds.extents.y : 0.0f,
|
||||
magnetBounceDuration,
|
||||
magnetCenterLeeway
|
||||
);
|
||||
|
||||
transform.position = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
if (speedIncreaseTimer > 0.0f)
|
||||
|
||||
Reference in New Issue
Block a user