Пример #1
0
        public override void Update()
        {
            Vector2 lv        = Vector2.zero;
            Vector2 follow    = Vector2.zero;
            Vector2 evade     = Vector2.zero;
            Vector2 separate  = Vector2.zero;
            Vector2 aligement = _direction;

            if (_leader != null)
            {
                lv  = -_leader._Velocity;
                lv  = lv.normalized;
                lv *= _LEADER_BEHIND_DIST;

                _behind._position = _leader._Position + lv;
                _behind._velocity = _leader._Velocity;
                //_arrive._target = _behind;
                _arrive.Update();
                follow = _arrive._steering;

                _ahead._position = _leader._Position - lv;
                _ahead._velocity = _leader._Velocity;
                float ld2 = (_host._Position - _leader._Position).sqrMagnitude;
                float ad2 = (_host._Position - _ahead._position).sqrMagnitude;
                float r2  = _LEADER_SIGHT_RADIUS * _LEADER_SIGHT_RADIUS;
                if (ld2 < r2 || ad2 < r2)
                {
                    //_ahead._position = _leader._Position - lv;
                    //_ahead._velocity = _leader._Velocity;
                    //_evade._target = _ahead;
                    _evade.Update();
                    evade = _evade._steering;
                }
            }

            //_separation._boids = _flockers;
            _separation.Update();
            separate  = _separation._steering;
            separate  = separate.normalized;
            separate *= _separation._WEIGHT;

            //_aligement._boids = _flockers;
            _aligement.Update();
            aligement = _aligement._direction.normalized;

            _steering  = follow + evade + separate;
            _direction = aligement;
        }
Пример #2
0
        public override void Update()
        {
            _aligement._boids  = _flockers;
            _cohesion._boids   = _flockers;
            _separation._boids = _flockers;

            _aligement.Update();
            _cohesion.Update();
            _separation.Update();

            Vector2 aligement  = _aligement._WEIGHT * _aligement._steering;
            Vector2 cohesion   = _cohesion._WEIGHT * _cohesion._steering;
            Vector2 separation = _separation._WEIGHT * _separation._steering;

            _steering  = aligement + cohesion + separation;
            _direction = _aligement._direction;
        }