Merge branch 'main' of https://homelab.tailf7f81b.ts.net/tschesky/AppleHillsProduction
This commit is contained in:
@@ -277,25 +277,22 @@ public class FollowerController: MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Command follower to go to a specific point (pathfinding mode)
|
||||
/// <summary>
|
||||
/// Command follower to go to a specific point (pathfinding mode).
|
||||
/// Make the follower move to a specific point only. Will not automatically return.
|
||||
/// </summary>
|
||||
/// <param name="worldPosition">The world position to move to.</param>
|
||||
public void GoToPoint(Vector2 worldPosition)
|
||||
/// <param name="targetPosition">The position to move to.</param>
|
||||
public void GoToPoint(Vector2 targetPosition)
|
||||
{
|
||||
_isManualFollowing = false;
|
||||
if (_pickupCoroutine != null)
|
||||
StopCoroutine(_pickupCoroutine);
|
||||
if (_aiPath != null)
|
||||
{
|
||||
_aiPath.enabled = true;
|
||||
_aiPath.maxSpeed = _followerMaxSpeed;
|
||||
_aiPath.destination = new Vector3(worldPosition.x, worldPosition.y, 0);
|
||||
}
|
||||
_pickupCoroutine = StartCoroutine(GoToPointSequence(targetPosition));
|
||||
}
|
||||
|
||||
// Command follower to go to a specific point and return to player
|
||||
/// <summary>
|
||||
/// Command follower to go to a specific point and return to player.
|
||||
/// Command follower to go to a specific point and return to player after a brief delay.
|
||||
/// Legacy method that combines GoToPoint and ReturnToPlayer for backward compatibility.
|
||||
/// </summary>
|
||||
/// <param name="itemPosition">The position of the item to pick up.</param>
|
||||
/// <param name="playerTransform">The transform of the player.</param>
|
||||
@@ -308,6 +305,19 @@ public class FollowerController: MonoBehaviour
|
||||
_pickupCoroutine = StartCoroutine(PickupSequence(itemPosition, playerTransform));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make the follower return to the player after it has reached a point.
|
||||
/// </summary>
|
||||
/// <param name="playerTransform">The transform of the player to return to.</param>
|
||||
public void ReturnToPlayer(Transform playerTransform)
|
||||
{
|
||||
if (_pickupCoroutine != null)
|
||||
StopCoroutine(_pickupCoroutine);
|
||||
if (_aiPath != null)
|
||||
_aiPath.maxSpeed = _followerMaxSpeed;
|
||||
_pickupCoroutine = StartCoroutine(ReturnToPlayerSequence(playerTransform));
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator PickupSequence(Vector2 itemPosition, Transform playerTransform)
|
||||
{
|
||||
_isManualFollowing = false;
|
||||
@@ -349,6 +359,63 @@ public class FollowerController: MonoBehaviour
|
||||
_aiPath.enabled = false;
|
||||
_pickupCoroutine = null;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator GoToPointSequence(Vector2 targetPosition)
|
||||
{
|
||||
_isManualFollowing = false;
|
||||
_isReturningToPlayer = false;
|
||||
|
||||
if (_aiPath != null)
|
||||
{
|
||||
_aiPath.enabled = true;
|
||||
_aiPath.maxSpeed = _followerMaxSpeed;
|
||||
_aiPath.destination = new Vector3(targetPosition.x, targetPosition.y, 0);
|
||||
}
|
||||
|
||||
// Wait until follower reaches target
|
||||
while (Vector2.Distance(new Vector2(transform.position.x, transform.position.y),
|
||||
new Vector2(targetPosition.x, targetPosition.y)) > GameManager.Instance.StopThreshold)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Signal arrival
|
||||
OnPickupArrived?.Invoke();
|
||||
|
||||
_pickupCoroutine = null;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator ReturnToPlayerSequence(Transform playerTransform)
|
||||
{
|
||||
if (_aiPath != null && playerTransform != null)
|
||||
{
|
||||
_aiPath.maxSpeed = _followerMaxSpeed;
|
||||
_aiPath.destination = playerTransform.position;
|
||||
}
|
||||
|
||||
_isReturningToPlayer = true;
|
||||
|
||||
// Wait until follower returns to player
|
||||
while (playerTransform != null &&
|
||||
Vector2.Distance(new Vector2(transform.position.x, transform.position.y),
|
||||
new Vector2(playerTransform.position.x, playerTransform.position.y)) > GameManager.Instance.StopThreshold)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_isReturningToPlayer = false;
|
||||
OnPickupReturned?.Invoke();
|
||||
|
||||
// Reset follower speed to normal after pickup
|
||||
_followerMaxSpeed = _defaultFollowerMaxSpeed;
|
||||
if (_aiPath != null)
|
||||
_aiPath.maxSpeed = _followerMaxSpeed;
|
||||
_isManualFollowing = true;
|
||||
if (_aiPath != null)
|
||||
_aiPath.enabled = false;
|
||||
|
||||
_pickupCoroutine = null;
|
||||
}
|
||||
#endregion Movement
|
||||
|
||||
#region ItemInteractions
|
||||
|
||||
Reference in New Issue
Block a user