Jump to content

[SOLVED] Issue with PathRoute creation


photo

Recommended Posts

Hello,

 

I'm having a little problem with implementing AI which looks like a beginner issue but I'm not able to figure it out. I'm trying to create an animated agent AI that moves towards another static agent(ally). Both these agents, a ground plane and a Nav sector of size 1024 * 1024 * 9 have been created in the world. 

 

I've created a custom AI class with a Node type member variable initialized using findNode(). Once that is successful I'm going into route creation.

This is what is done :

 

Init()

{

   route = new PathRoute(2.0f);

   route.setMaxAngle(0.5f);

   route.create2D(position, ally.position);

}

 

Update()

{

   float ifps = engine.game.getIFps();

   Vec3 dir = route.getPoint(1) - route.getPoint(0);

   if(length(dir) > EPSILON) {

      orientation = lerp(orientation, quat(setTo(Vec3_zero, dir, Vec3(0.0f, 0.0f, 1.0f))), iFps * 8.0f);

      position += self.getWorldDirection() * iFps * 16.0f;

      self.setWorldDirection(translate(position) * orientation);

   }

   route.renderVisualizer(vec4_one);

   route.create2D(position, ally.position);

}

 

Problem is with getPoint() call, the route is not being created and I'm getting route.getNumPoints() as 0.

ERROR : "PathRoute::getPointNum(): bad point number".

 

Have I missed something? Thanks in advance.

Link to comment

Do you have any obstacles between the entities? If not, the destination is directly reachable, and no additional points will be created. So before you are using the function getPoint(X), check with getNumPoints() your total number of points for your path.

Link to comment

No there are no obstacles between entities, the only entities present are the two AI nodes. If the destination is directly reachable, what should getNumPoints() return? For me its returning a value of 0, and PathRoute.isReady() is false. Thanks for the response.

Link to comment

If it returns 0 in your case, than that is totally okay, because of your straight line to your destination. And thats why you can't get your second path point wirg getPoint(1). What you can try to achieve is to insert a route.isReached() to check, if a valid path will be calculated.

 

EDIT: I noticed you are trying to calculate the route during the init-sequence? Than you have to use engine.world.updateSpatial() after the creation of your navmeshsectors.

Link to comment

I'm attaching the original cpp/world files for you to check. Oh yes I'll add updateSpatial(), thanks. I've seen route.getPoint(1) - route.getPoint(0) used often in demo codes. If number of path points being 0 is a valid condition, wouldn't this line error out everytime AI is in the final leg of its pathing?

ai_test.rar

Link to comment

Your right, I got 2 valid points for my path (the start and destination point). As far as I can see the script-file seems good for me, but add engine.world.updateSpatial() after transforming the Navmeshsector. If this doesn't help please send me your complete project and I will take a look over that.

Link to comment

Thanks Cristian for that! Adding engine.world.updateSpatial() solved the issue for me. Like you said, Since I had not updated BSP after calling 'new NavSector()', it assumed that there wasn't any Nav in the level so the next line route.create2D() did not create any path (hence numPoints() was 0). 

Link to comment
×
×
  • Create New...