1

I'm writing a 2d game in which an agent has to go to anywhere of large map, automatically.
Ofcourse, the map's got lots of obstacles, geometries, etc.

I decided to implement it with NavGraph (Navigation Graph), and read a very useful, great article here

After a few minutes, I worried about creating nav graph manually.

I googled hours to look up NavGraph generation tools, but there was nothing. (all result was for NavMesh, not NavGraph)

Is there anybody help me? Any suggestion or reply will be appreciated.
Thanks.

coding monster
  • 384
  • 4
  • 18
  • Just to clarify: Did you use a 3rd-party library for the `NavGraph`, or did you write your own system from scratch? If the latter, you'll definitely have to create it yourself in some way; whether that means writing custom tooling, or adapting your implementation to support some other common format – Human-Compiler Feb 10 '22 at 22:32
  • @Human-Compiler thanks for your reply, it was just to ask that anything by others exists - to save my time - – coding monster Feb 11 '22 at 11:17
  • 1
    In that case, in case you weren't aware: requesting recommendations for software/tools/etc is [off-topic for stack overflow](https://stackoverflow.com/help/on-topic) since it leads to opinionated answers. Its fine to ask for help with a specific problem, but questions requesting tooling or libraries are generally closed. I recommend keeping the question about solving generating nav graphs, rather than requesting tools – Human-Compiler Feb 11 '22 at 14:45
  • Also it may help to generate more answers if you can describe more about what you currently have, and what you have tried/done. If you have a `NavGraph` implementation you're using, either reference it, or have a quick snippet to describe how your implementation works so that people can (try) to provide answers. But keep in mind that you likely won't get recommendations for software/libraries since that's off-topic – Human-Compiler Feb 11 '22 at 14:49

1 Answers1

1

I used libpedsim enter image description hereenter image description here

It provides a framework to set waypoints and obstacles:

Ped::Tscene*                    pedscene;
Ped::Twaypoint*                 w1;
Ped::Tobstacle*                 o;

Waypoints were simply created by random sampling - we created a texture where red means it is blocked and otherwise the cell is free. The hacky implementation looked like this and worked pretty well:

// setup
pedscene = new Ped::Tscene(-200, -200, 400, 400);

loadMap();

srand(time(NULL));


int x;
int y;

for (int i = 0; i<agnentCount_/10; i++)
{ 
    Ped::Tagent *a = new Ped::Tagent();

    while(true)
    {
        x = rand() % 99;
        y = rand() % 99;
        
        if(texData[y * tex_->getWidth() + x][0]==255)
        {
            break;
        }

    }
    a->setPosition(
        x, 
        -y, 
        0.2);

    while(true)
    {
        x = std::rand() % 99;
        y = std::rand() % 99;
        
        if(texData[y * tex_->getWidth() + x][0]==255)
        {
            break;
        }
    }
    PathFind seeker(
        a->getPosition().x,
        -a->getPosition().y,
        x,
        y,
        tex_->getWidth(),
        tex_->getHeight(),
        texData);

    std::vector<buw::vector2i> path;
    path = seeker.findPath();

    for(std::vector<buw::vector2i>::iterator it = path.begin(); it!=path.end(); it++)
    {
        w1 = new Ped::Twaypoint( it->x(), -it->y(),  5);
        a->addWaypoint(w1);
    }

    pedscene->addAgent(a);
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90