Created
April 17, 2020 14:29
-
-
Save leochocolat/51a45a60b26823faf78ff6e3d21f5919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Code de base tu tuto: | |
void Update() | |
{ | |
foreach (FlockAgent agent in agents) | |
{ | |
List<Transform> context = GetNearbyObjects(agent); | |
//FOR DEMO ONLY | |
//agent.GetComponentInChildren<SpriteRenderer>().color = Color.Lerp(Color.white, Color.red, context.Count / 6f); | |
Vector2 move = behavior.CalculateMove(agent, context, this); | |
move *= driveFactor; | |
if (move.sqrMagnitude > squareMaxSpeed) | |
{ | |
move = move.normalized * maxSpeed; | |
} | |
agent.Move(move); | |
} | |
} | |
List<Transform> GetNearbyObjects(FlockAgent agent) | |
{ | |
List<Transform> context = new List<Transform>(); | |
Collider2D[] contextColliders = Physics2D.OverlapCircleAll(agent.transform.position, neighborRadius); | |
foreach (Collider2D c in contextColliders) | |
{ | |
if (c != agent.AgentCollider) | |
{ | |
context.Add(c.transform); | |
} | |
} | |
return context; | |
} | |
//avec mes changements | |
void Update() | |
{ | |
foreach (FlockAgent agent in agents) | |
{ | |
List<Transform> context = GetNearbyObjects(agent); | |
Vector3 move = behavior.CalculateMove(agent, context, this); | |
move *= driveFactor; | |
if (move.sqrMagnitude > squareMaxSpeed) | |
{ | |
move = move.normalized * maxSpeed; | |
} | |
agent.Move(move); | |
} | |
} | |
List<Transform> GetNearbyObjects(FlockAgent agent) | |
{ | |
List<Transform> context = new List<Transform>(); | |
foreach (FlockAgent item in agents) | |
{ | |
if (item != agent) | |
{ | |
Vector3 heading = item.AgentPosition - agent.AgentPosition; | |
if (heading.sqrMagnitude < squareNeighborRadius) | |
{ | |
context.Add(item.AgentTransform); | |
} | |
} | |
} | |
return context; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment