public override Vector3 Evaluate(IBoid boid) { Assert.IsNotNull(boid); var neighbors = boid.Neighbors; Assert.IsNotNull(neighbors); var n = neighbors.Count; var v = Vector3.zero; if (n <= 0) { return(v); } var position = boid.Transform.position; foreach (var other in neighbors) { var distance = other.Transform.position - position; if (distance.sqrMagnitude < 3 * 3) { v -= distance; } } return(v.normalized); }
// Use this for initialization void Start() { GameObject ballCarrier = GameObject.FindGameObjectWithTag("offense"); target = ballCarrier.GetComponent <OffensePlayerController>(); steering = new MovementManager(this); }
public override Vector3 Evaluate(IBoid boid) { Assert.IsNotNull(boid); var neighbors = boid.Neighbors; Assert.IsNotNull(neighbors); var n = neighbors.Count; var v = Vector3.zero; if (n <= 0) { return(v); } foreach (var other in neighbors) { v += other.Transform.forward; } var average = v / n; return(average.normalized); }
public override Vector3 Evaluate(IBoid boid) { Assert.IsNotNull(boid); var neighbors = boid.Neighbors; Assert.IsNotNull(neighbors); var n = neighbors.Count; var p = Vector3.zero; if (n <= 0) { return(p); } foreach (var other in neighbors) { p += other.Transform.position; } var centroid = p / n; return((centroid - boid.Transform.position).normalized); }
public xxxFollowLeader(IBoid host) { _host = host; _flockers = new List <IBoid>(); _behind = new Boid(); _behind._position = _host._Position; _behind._velocity = _host._Velocity; _behind._maxVelocity = _host._MaxVelocity; _ahead = new Boid(); _ahead._position = _host._Position; _ahead._velocity = _host._Velocity; _ahead._maxVelocity = _host._MaxVelocity; _arrive = new Arrive(_host); _evade = new Evade(_host); _separation = new Separation(_host); _aligement = new Aligement(_host); _separation._boids = _flockers; _aligement._boids = _flockers; _aligement._RADIUS = 15f; _separation._RADIUS = 3f; _aligement._WEIGHT = 1f; _separation._WEIGHT = 9f; }
void IBoidFoundHandler.OnBoidFound(IBoid boid) { Assert.AreNotEqual(this, boid); Assert.IsFalse(this.Neighbors.Contains(boid)); this.Neighbors.Add(boid); }
void IBoidLostHandler.OnBoidLost(IBoid boid) { Assert.AreNotEqual(this, boid); Assert.IsTrue(this.Neighbors.Contains(boid)); this.Neighbors.Remove(boid); }
public SeekTargetStrategy( IBoid host, float weight, ITarget target) : base(host, weight) { SeekTarget = target; }
public AbstractFleeStrategy( IBoid host, float weight, float proximityTreshold) : base(host, weight) { ProximityTreshold = proximityTreshold; }
Vector3 DoPursue(IBoid target) { float distanceToTarget = (NavPoint - target.NavPoint).magnitude; int t = Mathf.RoundToInt(distanceToTarget / maxSpeed); Vector3 futurePosition = target.NavPoint + target.Velocity * t; return(DoSeek(futurePosition)); }
Vector3 DoEvade(IBoid target) { float distanceToTarget = (host.NavPoint.position - target.NavPoint.position).magnitude; int t = Mathf.RoundToInt(distanceToTarget / host.MaxSpeed); Vector3 futurePosition = target.NavPoint.position + target.Velocity * t; return(DoFlee(futurePosition)); }
public PursuitStrategy( IBoid host, float weight, IBoid target) : base(host, weight) { PursuitTarget = target; }
public SeekStrategy( IBoid host, float weight, ref Vector3 target) : base(host, weight) { SeekTargetPosition = target; }
// Use this for initialization void Start() { GameObject defender = GameObject.FindGameObjectWithTag("defense"); defense = defender.GetComponent <DefensePlayerController>(); endzone = goalline.GetComponent <EndzoneScript>(); steering = new MovementManager(this); }
public FleeStrategy( IBoid host, float weight, float proximityTreshold, Vector3 fleeTarget) : base(host, weight, proximityTreshold) { FleeTargetPosition = fleeTarget; }
public EvadeStrategy( IBoid host, float weight, float proximityTreshold, IBoid target) : base(host, weight, proximityTreshold) { EvadeTarget = target; }
public FleeTargetStrategy( IBoid host, float weight, float proximityTreshold, ITarget fleeTarget) : base(host, weight, proximityTreshold) { FleeTarget = fleeTarget; }
private Vector3 doPursue(IBoid target) { Vector3 distance = target.GetPosition() - host.GetPosition(); float updates = distance.magnitude / host.GetMaxVelocity(); Vector3 tv = target.GetVelocity(); tv = this.ScaleBy(tv, updates); Vector3 targetFuture = target.GetPosition() + tv; return(doSeek(targetFuture, 10f)); }
public void Invoke(IBoid _host) { host = _host; vSteer = Vector3.zero; vDesired = Vector3.zero; _vDesired = Vector3.zero; NeighborDistSqr = NEIGHBOR_DISTANCE * NEIGHBOR_DISTANCE; CohereDistSqr = COHERE_DISTANCE * COHERE_DISTANCE; SeparateDistSqr = SEPARATE_DISTANCE * SEPARATE_DISTANCE; AlignDistSqr = ALIGN_DISTANCE * ALIGN_DISTANCE; }
public Evade(IBoid host) { _host = host; _boid = new Boid(); _boid._position = _host._Position; _boid._velocity = _host._Velocity; _boid._maxVelocity = _host._MaxVelocity; _flee = new Flee(_host); _flee._target = _boid; }
public Pursue(IBoid host) { _host = host; _spot = new Boid(); _spot._position = _host._Position; _spot._velocity = _host._Velocity; _spot._maxVelocity = _host._MaxVelocity; _seek = new Seek(_host); _seek._target = _spot; }
public SeparateStrategy( IBoid host, float weight, float sqrSeparationRadius, float separationIntensity, NeighborQuerier neighborQuerier) : base(host, weight) { _sqrSeparationRadius = sqrSeparationRadius; _separationIntensity = separationIntensity; _neighborQuerier = neighborQuerier; }
public LeaderFollowing( IBoid host, float followTailweight, IBoid leader, float maxDistancefromLead, float separateWeight, NeighborQuerier neighborQuerier, float separationRadius) : base(host, 1) { _leaderTail = new LeaderTail(leader, maxDistancefromLead); _arriveToleader = new SeekTargetStrategy(host, followTailweight, _leaderTail); _neighborsSeparation = new SeparateStrategy(host, separateWeight, separationRadius, 5, neighborQuerier); }
public void Init(float maxSpeed, bool useSteering) { BaseSteering[] steerings = gameObject.GetComponents <BaseSteering>(); for (int i = 0; i < steerings.Length; i++) { steeringBehaviours.Add(steerings[i]); steerings[i].Init(maxSpeed, this); } rb = GetComponent <Rigidbody2D>(); parent = gameObject.GetComponent <IBoid>(); this.useSteering = useSteering; EnableAvoidance(useAvoidance); }
public void BeginFollowLeader(IBoid leader, float arrivalRadius) { DeactivateAll(); EnableAvoidance(useAvoidance); foreach (BaseSteering steering in steeringBehaviours) { if (steering as FollowLeader) { FollowLeader newSteer = steering as FollowLeader; newSteer.SetActive(true); newSteer.SetLeader(leader); newSteer.SetSlowingRadius(arrivalRadius); } } }
bool GetNeighborAhead(out IBoid neighbor) { neighbor = null; Vector3 qAhead = Velocity.normalized * QUEUE_RADIUS; Vector3 checkPoint = centerProjectionPoint.position + qAhead; foreach (IBoid agent in GameCtrl.Instance.activeUnitsInGame) { if (agent != host && Vector3.Distance(checkPoint, agent.Position) <= QUEUE_RADIUS) { neighbor = agent; return(true); } } return(false); }
public Engagement(IBoid host) { _host = host; _flockers = new List <IBoid>(); _ahead = new Boid(); _ahead._position = _host._Position; _ahead._velocity = _host._Velocity; _ahead._maxVelocity = _host._MaxVelocity; _arrive = new Arrive(_host); _evade = new Evade(_host); _separation = new Separation(_host); _arrive._target = _target; _evade._target = _ahead; _separation._boids = _flockers; _separation._RADIUS = 1.0f; _separation._WEIGHT = 0.75f; }
public xxxFlock(IBoid host) { _host = host; _flockers = new List <IBoid>(); _cohesion = new Cohesion(_host); _aligement = new Aligement(_host); _separation = new Separation(_host); _cohesion._boids = _flockers; _aligement._boids = _flockers; _separation._boids = _flockers; _cohesion._RADIUS = 15f; _aligement._RADIUS = 15f; _separation._RADIUS = 3f; _cohesion._WEIGHT = 1f; _aligement._WEIGHT = 1f; _separation._WEIGHT = 10f; }
void OnTriggerEnter2D(Collider2D other) { IBoid otherBoid = other.GetComponentInParent <IBoid>(); if (otherBoid != null && !neighbors.Contains(otherBoid) && otherBoid as Boid != this) { neighbors.Add(otherBoid); } IStaticAvoidBoid otherStaticAvoid = other.GetComponentInParent <IStaticAvoidBoid>(); if (otherStaticAvoid != null && !staticAvoid.Contains(otherStaticAvoid)) { staticAvoid.Add(otherStaticAvoid); UpdateStaticAvoidance(); } IMobileAvoidBoid otheMobileAvoid = other.GetComponentInParent <IMobileAvoidBoid>(); if (otheMobileAvoid != null && !mobileAvoid.Contains(otheMobileAvoid)) { mobileAvoid.Add(otheMobileAvoid); } }
void OnTriggerExit2D(Collider2D other) { IBoid otherBoid = other.GetComponentInParent <IBoid>(); if (otherBoid != null) { neighbors.Remove(otherBoid); } IStaticAvoidBoid otherStaticBoid = other.GetComponentInParent <IStaticAvoidBoid>(); if (otherStaticBoid != null) { staticAvoid.Remove(otherStaticBoid); UpdateStaticAvoidance(); } IMobileAvoidBoid otherMobileBoid = other.GetComponentInParent <IMobileAvoidBoid>(); if (otherMobileBoid != null) { mobileAvoid.Remove(otherMobileBoid); } }