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); } }
// 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); } }
public void Update() { Vector2 direction = m_behaviour.CalculateMove(this); this.Move(direction, Time.deltaTime); }