private void EnterAStar() { if (pathfindingMode == PathfindingMode.AStar) { return; } if (pathfindingMode == PathfindingMode.Passive) { GridPathfinding.instance.HandleMobEnteredCombat(); } /* * if (GridPathfinding.instance.IsUsingPathfindingOptimization()) * { * if (!PathfindingOptimization.instance.AbleToRegisterPathfindingMob()) * { * pathfindingMode = PathfindingMode.Follow; * return; * } * } */ pathfindingMode = PathfindingMode.AStar; StopAllCoroutines(); StartCoroutine(GoAlongPathCoroutine()); if (!walkingSFX.isPlaying) { walkingSFX.Play(); } }
private void AdjustPathfindingMode() { if (pathfindingMode == PathfindingMode.Passive) { if (Vector3.Distance(mobRbody.position, PlayerCharacter.instance.transform.position) < engageCombatProximityNonWall) { if (!IsWallBetweenPositions(mobRbody.position, PlayerCharacter.instance.transform.position)) { EnterAStar(); } else { if (Vector3.Distance(mobRbody.position, PlayerCharacter.instance.transform.position) < engageCombatProximityThroughWall) { EnterAStar(); } } } } else { if (!IsWallInProximity(changeToFollowWallProximity)) { /* * if(GridPathfinding.instance.IsUsingPathfindingOptimization()) * { * if (pathfindingMode == PathfindingMode.AStar) * { * PathfindingOptimization.instance.UnregisterPathfindingMob(); * } * } */ pathfindingMode = PathfindingMode.Follow; } else { EnterAStar(); } } }
public static LinkedList <Tile> AStar(Character who, Tile target, TSession map, PathfindingMode mode) { InitializeOpenSetIfNecessary(map); pathfindingSearchId++; Tile start = who.Occupies; if (target == null) { return(null); } Tile closestToTargetSoFar = start; openSet.Clear(); int initH = Pathfinding.Heuristic(start, target); SetPathfindingInformation(start, pathfindingSearchId, false, 0, initH, null); openSet.Enqueue(start, initH); int closestToTargetHeuristicSoFar = initH; while (openSet.Count > 0) { Tile current = openSet.Dequeue(); if (current == target) { return(ReconstructPrettyPath(start, target)); } current.Pathfinding_Closed = true; foreach (var neighbour in current.Neighbours) // TODO change to traversable neighbours { // Tile neighbour = edge.Destination; if (neighbour.Pathfinding_EncounteredDuringSearch == pathfindingSearchId && neighbour.Pathfinding_Closed) { continue; } if (neighbour.BlocksMovement) { continue; } if (neighbour.Pathfinding_EncounteredDuringSearch < pathfindingSearchId) { SetPathfindingInformation(neighbour, pathfindingSearchId, false, int.MaxValue, int.MaxValue, current); openSet.Enqueue(neighbour, int.MaxValue); } int tentativeGScore = current.Pathfinding_G + (IsDiagonal(current, neighbour) ? 14 : 10); if (tentativeGScore >= neighbour.Pathfinding_G) { continue; } neighbour.Pathfinding_Parent = current; neighbour.Pathfinding_G = tentativeGScore; int heuristic = Heuristic(neighbour, target); neighbour.Pathfinding_F = neighbour.Pathfinding_G + heuristic; openSet.UpdatePriority(neighbour, neighbour.Pathfinding_F); if (heuristic < closestToTargetHeuristicSoFar) { closestToTargetSoFar = neighbour; closestToTargetHeuristicSoFar = heuristic; } } } if (mode == PathfindingMode.FindClosestIfDirectIsImpossible) { return(ReconstructPrettyPath(start, closestToTargetSoFar)); } return(null); }