TO SQUASH: Shark movement fixes.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user