I think there might be something wrong…?
Because there is always a target (either set with inspector, or as part of the Attack(CombatTarget combatTarget) lines, once the player is in range, the Stop() method is called every frame. Even if clicking for a normal move. No goot!
My solution was to simply add a line that clears the target after Stop() is called, freeing the player to move normally.
private void Update()
{
if (target == null) return;
CheckDistanceAndMove(); //this is locking the player in place.
}
private void CheckDistanceAndMove()
{
bool isInRange = (Vector3.Distance(target.position, transform.position) < weaponRange);
if (target !=null && !isInRange)
{
GetComponent<Mover>().MoveToDestination(target.position);
}
else
{
GetComponent<Mover>().Stop();
target = null;
}
}
public void Attack(CombatTarget combatTarget)
{
target = combatTarget.transform;
Debug.Log("have at you");
}