// Use this for initialization void Start() { Debug.Log("Setup started"); //GizmoManager.Instance.GizmoSubscribers += DrawGizmos; //Point in Triangle Test: Debug.Log("True expected: Is " + GeometryUtility.PointInTriangle(new Vector2(3, 3), new Vector2(1, 1), new Vector2(5, 1), new Vector2(3, 4))); Debug.Log("False expected: Is " + GeometryUtility.PointInTriangle(new Vector2(3, 3), new Vector2(1, 1), new Vector2(5, 1), new Vector2(3, 2))); //Point in Polygon Test: Debug.Log("True expected: Is " + GeometryUtility.PointInPolygon(new Vector2(3, 3), new Vector2[] { new Vector2(1, 1), new Vector2(5, 1), new Vector2(5, 5), new Vector2(1, 5) })); Debug.Log("False expected: Is " + GeometryUtility.PointInPolygon(new Vector2(2, 4), new Vector2[] { new Vector2(1, 1), new Vector2(5, 1), new Vector2(5, 5), new Vector2(3.5f, 3.5f) })); //TunnelArena arena = new TunnelArena(); //arena.AddWallsDefault(); //arena.AllWalls.ForEach(wall => wall.DrawGizmos()); //arena.AllWalls.ForEach(wall => Debug.Log(wall.ToString())); //arena.PlaceCoptersDefault(5); //arena.GetAllCopters().ForEach(copter => copter.DrawGizmos()); myArena = new TunnelArena(1.3f, 1.7f);//1.3, 3.7 //bool leaderPlaced = myArena.PlaceLeader(new Vector2(1.2f, 3.3f), 0.5f); bool leaderPlaced = myArena.PlaceLeader(new Vector2(1.2f, 2.7f), 0.5f); Debug.Log(leaderPlaced); myArena.PlaceCoptersDefault(20); //myArena.PlaceLeader(); myArena.Target = new Vector2(-8.2f, 0.8f);//-8.2, 1.8 GizmoManager.Instance.GizmoSubscribers += DrawText; }
public static void FollowerMovement(TunnelArena myArena, float speed) { List <Copter> followers = myArena.GetAllCopters();//Is the leader part of this list? No! //bool isLeaderPartOfList = followers.Contains(myArena.GetLeader()); //Debug.Log(isLeaderPartOfList); foreach (Copter follower in followers) { Vector2 movementVector = new Vector2(0.0f, 0.0f); movementVector += AvoidWalls(follower, myArena, 30, 0.5f);//With repulsionMagnitude = 3 and radius = 0.5f they still sometimes move through walls. movementVector += SwarmingFormulas.Function3(follower, myArena.GetLeader(), 0.5f, 20.0f, 0.6f); foreach (Copter otherCopter in followers) { if (otherCopter != follower) { movementVector += SwarmingFormulas.Function3(follower, otherCopter, 0.3f, 40.0f, 0.6f); } } if (movementVector.magnitude > 1.0f) { movementVector.Normalize(); } follower.SetPosition(follower.Position() + movementVector * speed); } }
private static Vector2 AvoidWalls(Copter copter, TunnelArena myArena, float repulsionMagnitude, float repulsionRadius) { Vector2 movementVector = new Vector2(0.0f, 0.0f); foreach (WallElement wall in myArena.AllWalls) { CollisionResult cr = copter.PolygonCircleCollision(wall.CornerPoints); movementVector += SwarmingFormulas.RepelWhenClose(cr.CollisionPointThisObject, cr.CollisionPointOtherObject, repulsionMagnitude, repulsionRadius); } return(movementVector); }
public static void LeaderMovement(TunnelArena myArena, float speed) { Copter leader = myArena.GetLeader(); Vector2 movementVector = new Vector2(0.0f, 0.0f); movementVector += SwarmingFormulas.AttractToTarget(leader, myArena.GetTarget(), 0.5f); movementVector += AvoidWalls(leader, myArena, 1, 0.1f); if (movementVector.magnitude > 1.0f) { movementVector.Normalize(); } leader.SetPosition(leader.Position() + (movementVector * speed)); }
// Update is called once per frame void Update() { Setup s = setup.GetComponent <Setup>(); TunnelArena ta = s.myArena; }
private static Vector2 AvoidWalls(Copter copter, TunnelArena myArena) { return(AvoidWalls(copter, myArena, 1, 0.5f)); }