TO SQUASH: Fucking magnets, how do they work?
This commit is contained in:
@@ -13,6 +13,20 @@ public class OozeBall : BallBase
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
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;
|
||||
|
||||
private float splitTimer = 10.0f;
|
||||
|
||||
private float tickTimer = 0.5f;
|
||||
@@ -23,8 +37,11 @@ public class OozeBall : BallBase
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
animator = GetComponent<Animator>();
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
selfCollider = GetComponent<Collider2D>();
|
||||
speed = new Vector2(Random.Range(-0.05f, 0.05f), Random.Range(-0.05f, 0.05f));
|
||||
|
||||
hasBoardBounds = TryCacheGameBoardBounds(out boardBounds);
|
||||
|
||||
audioSource.PlayOneShot(spawnSound);
|
||||
}
|
||||
|
||||
@@ -35,6 +52,35 @@ public class OozeBall : BallBase
|
||||
|
||||
if (stateInfo.IsName("OozeBallMove") || stateInfo.IsName("OozeBallSplit")) {
|
||||
transform.Translate(speed);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
splitTimer -= Time.deltaTime;
|
||||
|
||||
Reference in New Issue
Block a user