TO SQUASH: Shark movement fixes.
This commit is contained in:
@@ -54,6 +54,9 @@ public class Shark : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float alignmentThresholdDegrees = 5f;
|
private float alignmentThresholdDegrees = 5f;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private float targetTimeoutSeconds = 2f;
|
||||||
|
|
||||||
private SpriteRenderer sharkSpriteRenderer;
|
private SpriteRenderer sharkSpriteRenderer;
|
||||||
|
|
||||||
private Bounds? movementBounds = null;
|
private Bounds? movementBounds = null;
|
||||||
@@ -66,6 +69,8 @@ public class Shark : MonoBehaviour
|
|||||||
|
|
||||||
private float currentHeadingAngle = 0f;
|
private float currentHeadingAngle = 0f;
|
||||||
|
|
||||||
|
private float currentTargetTimer = 0f;
|
||||||
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@@ -93,6 +98,9 @@ public class Shark : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
|
// Foce reset the rotation.
|
||||||
|
transform.rotation = Quaternion.identity;
|
||||||
|
|
||||||
// Initialize gameBoardBounds.
|
// Initialize gameBoardBounds.
|
||||||
if (gameBoardSpriteRenderer != null && gameBoardBounds == null)
|
if (gameBoardSpriteRenderer != null && gameBoardBounds == null)
|
||||||
{
|
{
|
||||||
@@ -194,12 +202,22 @@ public class Shark : MonoBehaviour
|
|||||||
{
|
{
|
||||||
currentTarget = ChooseRandomTarget();
|
currentTarget = ChooseRandomTarget();
|
||||||
hasTarget = true;
|
hasTarget = true;
|
||||||
|
currentTargetTimer = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentTargetTimer += Time.fixedDeltaTime;
|
||||||
|
|
||||||
Vector2 toTarget = currentTarget - currentPosition;
|
Vector2 toTarget = currentTarget - currentPosition;
|
||||||
if (toTarget.sqrMagnitude <= targetReachedDistance * targetReachedDistance)
|
if (toTarget.sqrMagnitude <= targetReachedDistance * targetReachedDistance)
|
||||||
{
|
{
|
||||||
currentTarget = ChooseRandomTarget();
|
currentTarget = ChooseRandomTarget();
|
||||||
|
currentTargetTimer = 0f;
|
||||||
|
toTarget = currentTarget - currentPosition;
|
||||||
|
}
|
||||||
|
else if (currentTargetTimer >= targetTimeoutSeconds)
|
||||||
|
{
|
||||||
|
currentTarget = ChooseRandomTarget();
|
||||||
|
currentTargetTimer = 0f;
|
||||||
toTarget = currentTarget - currentPosition;
|
toTarget = currentTarget - currentPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user