public Vector2 GetRandomEntityPosition() { int attempts = 0; var position = new Vector2(); while (attempts < 1000) // shouldn't hardcode max attempts { position.x = Random.Range( World.Instance.Center.x - World.Instance.Size.x / 2, World.Instance.Center.x + World.Instance.Size.x / 2); position.y = Random.Range( World.Instance.Center.y - World.Instance.Size.y / 2, World.Instance.Center.y + World.Instance.Size.y / 2); if (!MovingEntity.IsEntityInObstacle(position) && GetClosestNodeToPosition(position) != NO_CLOSEST_NODE_FOUND) { return(position); } attempts++; } // give up. just return a random node position return(Graph.GetRandomNodePosition()); }
public Vector2 GetRandomEntityPosition(MovingEntity movingEntity) { int attempts = 0; var position = new Vector2(); while (attempts < 1000) // shouldn't hardcode max attempts { position.x = Random.Range(Center.x - Size.x / 2, Center.x + Size.x / 2); position.y = Random.Range(Center.y - Size.y / 2, Center.y + Size.y / 2); if (!movingEntity.IsEntityInObstacle(position)) { return(position); } attempts++; } // give up. just return a random node position return(position); }
public Vector2 GetRandomEntityPosition(MovingEntity movingEntity) { int attempts = 0; var position = new Vector2(); while (attempts < 1000) // shouldn't hardcode max attempts { position.x = Random.Range(Center.x - Size.x / 2, Center.x + Size.x / 2); position.y = Random.Range(Center.y - Size.y / 2, Center.y + Size.y / 2); if (!movingEntity.IsEntityInObstacle(position)) { return position; } attempts++; } // give up. just return a random node position return position; }