public void DoNonPenetrationLogic(SteeringCharacter aiCharacter) { List <SteeringCharacter> listOfCharacters = null; if (_cellSpacePartition != null) { listOfCharacters = _cellSpacePartition.GetCharactersAroundMe(aiCharacter); } else { listOfCharacters = _listOfAICharacters; } int aiCount = listOfCharacters.Count; SteeringCharacter currentChar = null; for (int i = 0; i < aiCount; ++i) { currentChar = listOfCharacters[i]; if (currentChar == aiCharacter) { continue; } Vector3 dirn = aiCharacter.Position - currentChar.Position; float dist = dirn.magnitude; dirn.Normalize(); float overlap = currentChar.radius + aiCharacter.radius - dist; if (overlap > 0) { aiCharacter.ForceSetPosition(aiCharacter.Position + dirn * overlap); } } }
public void StoreRefIfWithin(SteeringCharacter aiChar) { if (IsContained(aiChar.Position, aiChar.radius)) { _listOfAICharacters.Add(aiChar); } }
void Awake() { _decisionBrain = GetComponent <DecisionBrain>(); _steeringCharacter = GetComponent <SteeringCharacter>(); _scriptController = GetComponent <ScriptController>(); _transform = this.transform; _animator = GetComponent <Animator>(); }
public NavGridPath(NavGrid navGrid, SteeringCharacter aiCharacter) { _navGrid = navGrid; _cellGrid = _navGrid.GetCellGrid(); _path = new List <NavGrid.Cell>(); _totalPointsInPath = 0; _currentPathIndex = 0; _unvisitedCellsFPQ = new FastPriorityQueue <NavGrid.Cell>(_navGrid.rows * _navGrid.cols); _aiCharacter = aiCharacter; }
// Note: When calling this when CellSpacePartitioning is on, it only gets characters around the // neighboring cells of a character's cell for performance reasons public void GetNeighbors(ref List <SteeringCharacter> listOfNeighbors, SteeringCharacter currentChar, float radius, bool onlyWithGroup = false, int groupId = 0) { List <SteeringCharacter> charsToEvaluate = null; if (_cellSpacePartition != null) { charsToEvaluate = _cellSpacePartition.GetCharactersAroundMe(currentChar); } else { charsToEvaluate = _listOfAICharacters; } Vector3 dist; int count = charsToEvaluate.Count; SteeringCharacter aiChar = null; float radSquare = radius * radius; for (int i = 0; i < count; ++i) { aiChar = charsToEvaluate[i]; if (aiChar == currentChar) { continue; } if (onlyWithGroup) { if (aiChar.groupId != groupId) { continue; } } dist = aiChar.Position - currentChar.Position; if (dist.sqrMagnitude < radSquare) { listOfNeighbors.Add(aiChar); } } }
// Find characters in all cells the current character is and all neighboring cells public List <SteeringCharacter> GetCharactersAroundMe(SteeringCharacter aiChar) { List <Cell> cellsInRange = new List <Cell>(); Cell currentCell = null; for (int r = 0; r < rows; ++r) { for (int c = 0; c < cols; ++c) { currentCell = _grid[r, c]; if (currentCell.HasCharacter(aiChar)) { cellsInRange.Add(currentCell); } } } // Expand around these cells int numCellsInRange = cellsInRange.Count; if (numCellsInRange > 0) { for (int i = 0; i < numCellsInRange; ++i) { int neighborsCount = cellsInRange[i].neighbors.Count; Cell neighborCell = null; for (int j = 0; j < neighborsCount; ++j) { neighborCell = cellsInRange[i].neighbors[j]; if (neighborCell.HasCharacters() && !cellsInRange.Contains(neighborCell)) { cellsInRange.Add(neighborCell); } } } } return(GetListOfUniqueCharacters(cellsInRange)); }
public void RemoveCharacter(SteeringCharacter aiChar) { _listOfAICharacters.Remove(aiChar); }
public void AddCharacter(SteeringCharacter aiChar) { _listOfAICharacters.Add(aiChar); }
public bool HasCharacter(SteeringCharacter aiChar) { return(IsContained(aiChar.Position, aiChar.radius)); }
public bool HasCharacter(SteeringCharacter aiChar) { return(_listOfAICharacters.Contains(aiChar)); }
virtual protected void Init() { _steeringCharacter = GetComponent <SteeringCharacter>(); _steeringCharacter.AddBehavior(this); }