Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        GameObject ballCarrier = GameObject.FindGameObjectWithTag("offense");

        target   = ballCarrier.GetComponent <OffensePlayerController>();
        steering = new MovementManager(this);
    }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        void IBoidFoundHandler.OnBoidFound(IBoid boid)
        {
            Assert.AreNotEqual(this, boid);
            Assert.IsFalse(this.Neighbors.Contains(boid));

            this.Neighbors.Add(boid);
        }
Exemplo n.º 7
0
        void IBoidLostHandler.OnBoidLost(IBoid boid)
        {
            Assert.AreNotEqual(this, boid);
            Assert.IsTrue(this.Neighbors.Contains(boid));

            this.Neighbors.Remove(boid);
        }
Exemplo n.º 8
0
 public SeekTargetStrategy(
     IBoid host,
     float weight,
     ITarget target)
     : base(host, weight)
 {
     SeekTarget = target;
 }
Exemplo n.º 9
0
 public AbstractFleeStrategy(
     IBoid host,
     float weight,
     float proximityTreshold)
     : base(host, weight)
 {
     ProximityTreshold = proximityTreshold;
 }
Exemplo n.º 10
0
    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));
    }
Exemplo n.º 11
0
    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));
    }
Exemplo n.º 12
0
 public PursuitStrategy(
     IBoid host,
     float weight,
     IBoid target)
     : base(host, weight)
 {
     PursuitTarget = target;
 }
Exemplo n.º 13
0
 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);
    }
Exemplo n.º 15
0
 public FleeStrategy(
     IBoid host,
     float weight,
     float proximityTreshold,
     Vector3 fleeTarget)
     : base(host, weight, proximityTreshold)
 {
     FleeTargetPosition = fleeTarget;
 }
Exemplo n.º 16
0
 public EvadeStrategy(
     IBoid host,
     float weight,
     float proximityTreshold,
     IBoid target)
     : base(host, weight, proximityTreshold)
 {
     EvadeTarget = target;
 }
Exemplo n.º 17
0
 public FleeTargetStrategy(
     IBoid host,
     float weight,
     float proximityTreshold,
     ITarget fleeTarget)
     : base(host, weight, proximityTreshold)
 {
     FleeTarget = fleeTarget;
 }
Exemplo n.º 18
0
    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));
    }
Exemplo n.º 19
0
 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;
 }
Exemplo n.º 20
0
        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;
        }
Exemplo n.º 21
0
        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;
        }
Exemplo n.º 22
0
 public SeparateStrategy(
     IBoid host,
     float weight,
     float sqrSeparationRadius,
     float separationIntensity,
     NeighborQuerier neighborQuerier)
     : base(host, weight)
 {
     _sqrSeparationRadius = sqrSeparationRadius;
     _separationIntensity = separationIntensity;
     _neighborQuerier     = neighborQuerier;
 }
Exemplo n.º 23
0
 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);
 }
Exemplo n.º 24
0
    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);
    }
Exemplo n.º 25
0
    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);
            }
        }
    }
Exemplo n.º 26
0
    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);
    }
Exemplo n.º 27
0
        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;
        }
Exemplo n.º 28
0
        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;
        }
Exemplo n.º 29
0
    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);
        }
    }
Exemplo n.º 30
0
    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);
        }
    }