Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To perform every tick
- public override void MovementTick()
- {
- GridObject lowestCostObject = aiFinder.LowestCostObject();
- Tile targetTile = lowestCostObject.currentTile;
- currentTilePath = pathfinding.FindPath(headBody.gridObject.currentTile, targetTile);
- if (currentTilePath != null)
- {
- MoveHeadToTile(currentTilePath[0]);
- return;
- }
- // If can't find an object, it will try to move to a random valid neighbour
- Tile randomValidTile = RandomValidTile();
- if (randomValidTile == null)
- {
- // Move up and die if there's no valid neighbours
- MoveHeadToTile(headBody.gridObject.currentTile.neighbourTiles[(int)Direction.Up]);
- return;
- }
- // Move to random tile if path wasn't found
- MoveHeadToTile(randomValidTile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement