I decided not to use raycasting since some objects may be pushed and I wouldn’t want them to stop NPC from moving.
Here’s what I currently ended up with (rough idea):
public IEnumerator IsStuckCheck()
{
while (true)
{
Vector2 oldPos = transform.position;
yield return new WaitForSeconds(0.5f);
Vector2 newPos = transform.position;
if (Vector2.Distance(newPos, oldPos) <= 0.5f)
isStuck = true;
}
}
After some testing it seems be quite reliable, however I am still open to better suggestions.