コード例 #1
0
 protected override void IdleAction()
 {
     if (!PathFinderReady)
     {
         return;
     }
     StateChange.ToFindTargetState();
 }
コード例 #2
0
        protected override void MoveCharacter()
        {
            if (_usingPath)
            {
                if (_gdi != null && !_isMoving)
                {
                    StopCoroutine(_gdi);
                    _element = 0;
                }

                if (Vector3.Distance(transform.position, _path.ElementAt(_element)) < float.Epsilon)
                {
                    _element++;
                }

                if (_element < _path.Count())
                {
                    MoveAcrossPath(_path.ElementAt(_element));
                }
            }
            else
            {
                if (canAttack && _target && !_attackCooldown)
                {
                    if (Vector3.Distance(_rb.position, _target.transform.position) < attackDistance)
                    {
                        StateChange.ToAttackState();
                    }
                }

                if (_attackCooldown && _rb.isKinematic == false)
                {
                    if (_timer <= _attackCooldownTime - 2)
                    {
                        _rb.isKinematic = true;
                    }
                }

                if (_rb.isKinematic)
                {
                    Vector3 direction = _goalPosition - _rb.position;
                    _rb.MovePosition(_rb.position + direction * movementSpeed * Time.deltaTime);
                    //transform.Rotate(direction, Space.Self);
                }


                if (!(Vector3.Distance(_rb.position, _goalPosition) < 1))
                {
                    return;
                }
                StateChange.ToFindTargetState();
            }
        }
コード例 #3
0
 protected override void Attack()
 {
     _rb.isKinematic = false;
     if (_rb)
     {
         Vector3 direction = _target.transform.position - _rb.position;
         _rb.AddForce(direction * (movementSpeed * attackValue), ForceMode.Impulse);
     }
     _timer          = _attackCooldownTime;
     _attackCooldown = true;
     StateChange.ToFindTargetState();
 }
コード例 #4
0
        private void MoveAcrossPath(Vector3 location)
        {
            _isMoving = true;

            transform.position =
                Vector3.MoveTowards(transform.position, location, movementSpeed * Time.deltaTime);
            if (!(Vector3.Distance(transform.position, _goalPosition) < 1))
            {
                return;
            }
            _usingPath = false;
            StateChange.ToFindTargetState();
            _isMoving = false;
        }
コード例 #5
0
        protected override void IdleAction()
        {
            //if (Math.Abs(_sphere.radius - moveableRadius) > float.Epsilon) _sphere.radius = moveableRadius;
            for (int i = 0; i < _flockTotal; i++)
            {
                GameObject clone = Instantiate(_boid);
                clone.transform.position = transform.position + Random.insideUnitSphere * _spawnRadius;
                _boidSwarm.Add(clone.GetComponent <FlyingBoid>());
            }
            foreach (var boid in _boidSwarm)
            {
                foreach (var t in _boidSwarm.Where(t => !boid.NeighboursRigidbodies.Contains(t.BoidRigidbody) && t != boid))
                {
                    boid.AddNeighbour(t.BoidRigidbody);
                }
                boid.AddLeader(_rb);
            }

            if (_boidSwarm.Count == _flockTotal)
            {
                StateChange.ToFindTargetState();
            }
        }