TO SQUASH: Shark movement fixes.

This commit is contained in:
2026-08-11 21:55:16 -04:00
parent e1c418499f
commit 69beb2496d
+18
View File
@@ -54,6 +54,9 @@ public class Shark : MonoBehaviour
[SerializeField]
private float alignmentThresholdDegrees = 5f;
[SerializeField]
private float targetTimeoutSeconds = 2f;
private SpriteRenderer sharkSpriteRenderer;
private Bounds? movementBounds = null;
@@ -66,6 +69,8 @@ public class Shark : MonoBehaviour
private float currentHeadingAngle = 0f;
private float currentTargetTimer = 0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
@@ -93,6 +98,9 @@ public class Shark : MonoBehaviour
// Update is called once per frame
void FixedUpdate()
{
// Foce reset the rotation.
transform.rotation = Quaternion.identity;
// Initialize gameBoardBounds.
if (gameBoardSpriteRenderer != null && gameBoardBounds == null)
{
@@ -194,12 +202,22 @@ public class Shark : MonoBehaviour
{
currentTarget = ChooseRandomTarget();
hasTarget = true;
currentTargetTimer = 0f;
}
currentTargetTimer += Time.fixedDeltaTime;
Vector2 toTarget = currentTarget - currentPosition;
if (toTarget.sqrMagnitude <= targetReachedDistance * targetReachedDistance)
{
currentTarget = ChooseRandomTarget();
currentTargetTimer = 0f;
toTarget = currentTarget - currentPosition;
}
else if (currentTargetTimer >= targetTimeoutSeconds)
{
currentTarget = ChooseRandomTarget();
currentTargetTimer = 0f;
toTarget = currentTarget - currentPosition;
}