private void MoveEntity(RankedTagReaction reaction) { // If not reacting to anything, keep moving to the current target. if (reaction == null) { MoveTowardsTarget(_currentTarget.transform.position); return; } // If the behavior is to avoid or purse, change targets. if (reaction.Behavior == AIBehavior.Avoid || reaction.Behavior == AIBehavior.Pursue) { _currentTarget = reaction.ReactToObject; } // Move away from an object we want to avoid. Otherwise, // Move towards a pursued object, or my current target position. switch (reaction.Behavior) { case AIBehavior.Avoid: MoveAwayFromTarget(_currentTarget.transform.position); break; default: MoveTowardsTarget(_currentTarget.transform.position); break; } }
private RankedTagReaction GetStrongestReactionToSensedEntities(List <GameObject> sensedEntities) { int winningPriority = 0; RankedTagReaction winningReaction = null; for (int i = 0; i < sensedEntities.Count; i++) { GameObject current = sensedEntities[i]; RankedTagReaction reaction; try { reaction = GetReactionForTag(current.tag); } catch (MissingReferenceException) { // The object no longer exists. Choose something else. continue; } if (reaction == null) { continue; } if (reaction.Rank <= winningPriority) { continue; } winningReaction = reaction; winningReaction.ReactToObject = current; } return(winningReaction); }
private RankedTagReaction GetReactionForTag(string tag) { RankedTagReaction result = null; for (int i = 0; i < Reactions.Count; i++) { RankedTagReaction current = Reactions[i]; if (tag != current.Tag) { continue; } result = current; } return(result); }
private void EvaluateSenses() { if (_currentTarget == null) { _currentTarget = MatchWaypointManager.FindNearestWaypoint(transform.position); Animator.Play(MoveAnimation); } if (_currentTarget.tag == "Waypoint" && Vector3.Distance(transform.position, _currentTarget.transform.position) < 1.0f) { // TODO: Wait for a couple of seconds in the wait animation, then move again! _currentTarget = MatchWaypointManager.FindRandomWaypointInRange(transform.position, _currentTarget); } List <GameObject> sensedEntities = Detector.SensedEntities; _lastReaction = GetStrongestReactionToSensedEntities(sensedEntities); MoveEntity(_lastReaction); }