diff --git a/Assets/Scripts/Game/Shark.cs b/Assets/Scripts/Game/Shark.cs index c87ca0c..09addb7 100644 --- a/Assets/Scripts/Game/Shark.cs +++ b/Assets/Scripts/Game/Shark.cs @@ -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; }