// Update is called once per frame void Update() { // move agents foreach (FlockAgent agent in agents) { List <Transform> context = GetNearbyObjects(agent); // demo only, badly optimized //agent.GetComponentInChildren<Renderer>().material.SetColor("_BaseColor", Color.Lerp(Color.white, Color.red, context.Count / 100f)); Vector3 move = behaviour.CalculateMove(agent, context, this); move *= driveFactor; if (move.sqrMagnitude > squareMaxSpeed) { move = move.normalized * maxSpeed; } agent.Move(move); } }
// Update is called once per frame void Update() { foreach (FlockAgent agent in agents) { List <Transform> context = GetNearbyObjects(agent); //agent.GetComponentInChildren<SpriteRenderer>().color = Color.Lerp(Color.white, Color.red, context.Count/6f); Vector2 move = behaviour.CalculateMove(agent, context, this); move *= driveFactor; if (move.sqrMagnitude > squareMaxSpeed) { move = move.normalized * maxSpeed; } agent.Move(move, context.Count); if (agent.flockLeader == null) { //agent.GetComponentInChildren<SpriteRenderer>().color = BaseBoidColor; agent.GetComponentInChildren <Renderer>().material.SetColor("_Color", BaseBoidColor); } else { Vector2 centerOffset = (Vector2)agent.flockLeader.transform.position - (Vector2)agent.transform.position; //agent.GetComponentInChildren<SpriteRenderer>().color = Color.Lerp(agent.flockLeader.GetComponentInChildren<SpriteRenderer>().color, BaseBoidColor, (centerOffset.magnitude/5) - 1); agent.GetComponentInChildren <Renderer>().material.SetColor("_Color", Color.Lerp(agent.flockLeader.GetComponentInChildren <Renderer>().sharedMaterial.color, BaseBoidColor, (centerOffset.magnitude / leaderRadius) - 1)); //agent.GetComponentInChildren<Renderer>().material.SetColor("_Color", agent.flockLeader.GetComponentInChildren<Renderer>().sharedMaterial.color); } if (agent.flockLeader == agent && agent.isPlayer && !gameEnd) { cameraController.MoveCameraTo(agent.transform.position); behaviour.weights[5] = 2; } else if (gameEnd) { cameraController.MoveCameraTo(Vector3.zero); behaviour.weights[5] = 0; } } }