paulbreuler / Pathfinding

A* path finding setup in Unity based on 3D grid
MIT License
20 stars 4 forks source link

AI Node Update when stopped #5

Closed paulbreuler closed 6 years ago

paulbreuler commented 6 years ago

AI was waiting for next action timer before updating nodes to unwalkable. Temporary fix applied.

// If we don't check !isMoving the AI may get stuck waiting to update the grid for nextActionTime. if (isSafeToUpdatePath || (!isMoving)) UpdateNodePosition();

Need to update nodes only on stop and start of movement rather than each frame we are stopped.

paulbreuler commented 6 years ago

Fixed by adding a check to prevent actions until the unit is moving again. Also, updated the next action interval to prevent default values from causing the timer to always be greater than nextActionTime resulting in updates every frame.

// If we don't check !isMoving the AI may get stuck waiting to update the grid for nextActionTime. if (isSafeToUpdatePath || (!isMoving && isTargetReached && !preventExtraNodeUpdate)) { preventExtraNodeUpdate = true; UpdateNodePosition(); }