コード例 #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);
        }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        GameObject ballCarrier = GameObject.FindGameObjectWithTag("offense");

        target   = ballCarrier.GetComponent <OffensePlayerController>();
        steering = new MovementManager(this);
    }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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;
        }
コード例 #6
0
        void IBoidFoundHandler.OnBoidFound(IBoid boid)
        {
            Assert.AreNotEqual(this, boid);
            Assert.IsFalse(this.Neighbors.Contains(boid));

            this.Neighbors.Add(boid);
        }
コード例 #7
0
        void IBoidLostHandler.OnBoidLost(IBoid boid)
        {
            Assert.AreNotEqual(this, boid);
            Assert.IsTrue(this.Neighbors.Contains(boid));

            this.Neighbors.Remove(boid);
        }
コード例 #8
0
 public SeekTargetStrategy(
     IBoid host,
     float weight,
     ITarget target)
     : base(host, weight)
 {
     SeekTarget = target;
 }
コード例 #9
0
 public AbstractFleeStrategy(
     IBoid host,
     float weight,
     float proximityTreshold)
     : base(host, weight)
 {
     ProximityTreshold = proximityTreshold;
 }
コード例 #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));
    }
コード例 #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));
    }
コード例 #12
0
 public PursuitStrategy(
     IBoid host,
     float weight,
     IBoid target)
     : base(host, weight)
 {
     PursuitTarget = target;
 }
コード例 #13
0
 public SeekStrategy(
     IBoid host,
     float weight,
     ref Vector3 target)
     : base(host, weight)
 {
     SeekTargetPosition = target;
 }
コード例 #14
0
    // Use this for initialization
    void Start()
    {
        GameObject defender = GameObject.FindGameObjectWithTag("defense");

        defense  = defender.GetComponent <DefensePlayerController>();
        endzone  = goalline.GetComponent <EndzoneScript>();
        steering = new MovementManager(this);
    }
コード例 #15
0
 public FleeStrategy(
     IBoid host,
     float weight,
     float proximityTreshold,
     Vector3 fleeTarget)
     : base(host, weight, proximityTreshold)
 {
     FleeTargetPosition = fleeTarget;
 }
コード例 #16
0
ファイル: EvadeStrategy.cs プロジェクト: FloRul/RitFlocking
 public EvadeStrategy(
     IBoid host,
     float weight,
     float proximityTreshold,
     IBoid target)
     : base(host, weight, proximityTreshold)
 {
     EvadeTarget = target;
 }
コード例 #17
0
 public FleeTargetStrategy(
     IBoid host,
     float weight,
     float proximityTreshold,
     ITarget fleeTarget)
     : base(host, weight, proximityTreshold)
 {
     FleeTarget = fleeTarget;
 }
コード例 #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));
    }
コード例 #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;
 }
コード例 #20
0
ファイル: Evade.cs プロジェクト: CrazyFizik/Lunar-Rescuer
        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;
        }
コード例 #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;
        }
コード例 #22
0
 public SeparateStrategy(
     IBoid host,
     float weight,
     float sqrSeparationRadius,
     float separationIntensity,
     NeighborQuerier neighborQuerier)
     : base(host, weight)
 {
     _sqrSeparationRadius = sqrSeparationRadius;
     _separationIntensity = separationIntensity;
     _neighborQuerier     = neighborQuerier;
 }
コード例 #23
0
ファイル: LeaderFollowing.cs プロジェクト: FloRul/RitFlocking
 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);
 }
コード例 #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);
    }
コード例 #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);
            }
        }
    }
コード例 #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);
    }
コード例 #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;
        }
コード例 #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;
        }
コード例 #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);
        }
    }
コード例 #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);
        }
    }