public override void generateTransitions(ref DefaultState currentState, ref DefaultState previousState, ref DefaultState idealGoalState, ref List <DefaultAction> transitions) { transitions.Clear(); ARAstarState ACurrentState = currentState as ARAstarState; bool[] transitionsPossible = new bool[8]; // doing non-diagonals first for (int i = 0; i < transitionsList.Count; i += 2) { Collider [] colliders = Physics.OverlapSphere(ACurrentState.state + transitionsList[i], 0.25F, layer); //if (! Physics.CheckSphere(ACurrentState.state + transitionsList[i],0.5F,layer)) if (colliders.Count() == 0) { transitionsPossible[i] = true; ARAstarAction action = new ARAstarAction(); action.cost = Vector3.Distance(ACurrentState.state, ACurrentState.state + transitionsList[i]); action.direction = transitionsList[i]; ARAstarState st = new ARAstarState(ACurrentState.state + transitionsList[i]); action.state = st; transitions.Add(action); } else { transitionsPossible[i] = false; // TODO: register the non deterministic obstacle here foreach (Collider collider in colliders) { NonDeterministicObstacle nonDeterministicObstacle = collider.GetComponent <NonDeterministicObstacle>(); if (nonDeterministicObstacle == null) { } // Debug.LogWarning("planner collided with something that is not a non deterministic obtacle " + collider.name) ; else { if (planningTask != null && _currentObservedNonDeterministicObstacles.Contains(nonDeterministicObstacle) == false) // not using a planning task, no need to register { Debug.LogError("NON DET OBSTACLE " + collider.name); //nonDeterministicObstacle.observable.registerObserver(Event.NON_DETERMINISTIC_OBSTACLE_CHANGED,planningTask); _currentObservedNonDeterministicObstacles.Add(nonDeterministicObstacle); } } } } } // diagonals for (int i = 1; i < transitionsList.Count; i += 2) { Collider [] colliders = Physics.OverlapSphere(ACurrentState.state + transitionsList[i], 0.25F, layer); //if (! Physics.CheckSphere(ACurrentState.state + transitionsList[i],0.5F,layer)) if (colliders.Count() == 0) { if (transitionsPossible[i - 1] == true || transitionsPossible[(i + 1) % transitionsList.Count] == true) { transitionsPossible[i] = true; ARAstarAction action = new ARAstarAction(); action.cost = Vector3.Distance(ACurrentState.state, ACurrentState.state + transitionsList[i]); action.direction = transitionsList[i]; ARAstarState st = new ARAstarState(ACurrentState.state + transitionsList[i]); action.state = st; transitions.Add(action); } else { transitionsPossible[i] = false; } } else { transitionsPossible[i] = false; // TODO: register the non deterministic obstacle here foreach (Collider collider in colliders) { NonDeterministicObstacle nonDeterministicObstacle = collider.GetComponent <NonDeterministicObstacle>(); if (nonDeterministicObstacle == null) { } // Debug.LogWarning("planner collided with something that is not a non deterministic obtacle " + collider.name); else { if (planningTask != null && _currentObservedNonDeterministicObstacles.Contains(nonDeterministicObstacle) == false) // not using a planning task, no need to register { Debug.Log("NON DET OBSTACLE " + collider.name); //nonDeterministicObstacle.observable.registerObserver(Event.NON_DETERMINISTIC_OBSTACLE_CHANGED,planningTask); _currentObservedNonDeterministicObstacles.Add(nonDeterministicObstacle); } } } } } }
public static uint UpdatePolygonDictionary(Vector3 currentPosition, uint currentPolygonIndex, NonDeterministicObstacle nonDeterministicObstacle) { uint newPolygonIndex = GlobalNavigator.recastSteeringManager.GetClosestPolygon(currentPosition); if (newPolygonIndex != currentPolygonIndex) { GlobalNavigator.recastSteeringManager.DecrNumObjectsInPolygon(currentPolygonIndex); GlobalNavigator.recastSteeringManager.IncrNumObjectsInPolygon(newPolygonIndex); if (polygonDictionary.ContainsKey(currentPolygonIndex)) { _IncrementNumberOfChangesInPolygon(currentPolygonIndex); if (nonDeterministicObstacle != null) { polygonDictionary[currentPolygonIndex].nonDeterministicObstacles.Remove(nonDeterministicObstacle); } } if (polygonDictionary.ContainsKey(newPolygonIndex)) { _IncrementNumberOfChangesInPolygon(newPolygonIndex); if (nonDeterministicObstacle != null) { polygonDictionary[newPolygonIndex].nonDeterministicObstacles.Add(nonDeterministicObstacle); } } } return(newPolygonIndex); }