public override void GetSteeringBehaviorVector(out Vector3 steer, SteeringAgent mine, SurroundingsContainer surroundings) { Vector3 fleeMidpoint = Vector3.zero; float count = 0; foreach (Agent other in GetFilteredAgents(surroundings, this)) { if (WithinEffectiveRadius(mine, other)) { fleeMidpoint += (other.Position); count++; } } if (count > 0) { fleeMidpoint /= (count); mine.GetSteerVector(out steer, (mine.Position - fleeMidpoint)); mine.SetAgentProperty(fleeAttributeName, true); } else { mine.SetAgentProperty(fleeAttributeName, false); steer = Vector3.zero; } }
public override void GetSteeringBehaviorVector(out Vector3 steer, SteeringAgent mine, SurroundingsContainer surroundings) { steer = Vector3.zero; int count = 0; foreach (Agent other in GetFilteredAgents(surroundings, this)) { if (WithinEffectiveRadius(mine, other)) { Vector3 diff = mine.Position - other.Position; if (diff.sqrMagnitude < .001f) { diff = UnityEngine.Random.insideUnitCircle * .01f; } steer += (diff.normalized / diff.magnitude); count++; } } if (count > 0) { steer /= ((float)count); } if (steer.magnitude > 0) { mine.GetSteerVector(out steer, steer); } }
public override void GetSteeringBehaviorVector(out Vector3 steer, SteeringAgent mine, SurroundingsContainer surroundings) { Vector3 sum = Vector3.zero; int count = 0; foreach (Agent other in GetFilteredAgents(surroundings, this)) { if (WithinEffectiveRadius(mine, other)) { float modFactor = 1; sum += (other.Velocity) * modFactor; count++; } } if (count > 0) { sum /= ((float)count); mine.GetSteerVector(out steer, sum); } else { steer = Vector3.zero; } }