Пример #1
0
 private void FixedUpdate()
 {
     foreach (var agent in _boidSwarm)
     {
         var neighbours = GetNearbyObjects(agent);
         var move       = _behaviour.CalculateMove(agent, neighbours, this);
         move *= _driveFactor;
         if (move.sqrMagnitude > _squareMaxSpeed)
         {
             move = move.normalized * _maxSpeed;
         }
         agent.MoveBoid(move);
     }
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        foreach (BoidAgent agent in agents)
        {
            List <Transform> context = GetNearbyBoids(agent);

            // In order to check this functionality, we can change the color of the boid depending on the number of neighbors
            // This is really slow and should only be used for debugging purposes
            // const float numNeighbors = 6f;
            // agent.GetComponentInChildren<SpriteRenderer>().color = Color.Lerp(Color.white, Color.red, context.Count / numNeighbors);

            Vector2 move = behaviour.CalculateMove(agent, context, this);
            move *= driveFactor;

            if (move.sqrMagnitude > sqrMaxSpeed)
            {
                move = move.normalized * maxSpeed;
            }

            agent.Move(move);
        }
    }
Пример #3
0
    public void Update()
    {
        Vector2 direction = m_behaviour.CalculateMove(this);

        this.Move(direction, Time.deltaTime);
    }