In my game, there is a NPC that follows Waypoints in a sort of maze style game. Its movement is done through the Character Controller function : Move. Sometimes it gets stuck. If move gets called every frame (in the Update())... How would you check every 'x' seconds if the object has changed its position by 'y' much?
Thank you very much!
var lastCheckTime = 0;
var lastCheckPos : Vector3;
var xSeconds = 3.0;
var yMuch = 1.0;
if ((Time.time - lastCheckTime) > xSeconds)
if (npc.transform.pos - lastCheckPos).magnitude < yMuch)
lastCheckPos = npc.transform.pos;
lastCheckTime = Time.time;
Note this is untested and won't compile but should give you the idea.
Also, it will count as 'unmoved' if the npc moves away but then moves back before the next check comes around. To get around that, check more often, and increment a counter of when it hasn't moved. If that count reaches a certain threshold, then panic.