Artificial Intelligence Tools Extension (Beta Release 8)

dtishin

  • *
  • Posts: 82
Thanks Robert, I updated the code in the .hx file but the game still crashes :(
I'll appreciate if you could take a look at the screenshots of my event code (I copied all screens that I think could be relevant):
https://www.dropbox.com/sh/dxn9cbjddmnzg87/AAAmbxwa3dEHkA6iVMW9mLtRa?dl=0

I'm really puzzled by this error, because I execute your pathfinding AI code only if the "path_initiated" attribute is true (see "chasing the avatar p3" event), but the only setter of this boolean to "true" happens immediately after I define the start / finish rows and columns (see "chasing the avatar p2" event). So I'm wondering how the AI logic can run at all if the terminal nodes are not defined...

dtishin

  • *
  • Posts: 82
Hey, it seems like I figured out the root cause! And maybe it's worth including into your documentation:
When I specified the start / finish tiles of the graph, I used the block "get column (x) coordinate of [x coordinate of actor]  in scene" and similar block for the row (which I suppose makes perfect sense). The problem is that the actual x / y coordinate of an actor is by default offset by half a tile relative to the centre of a tile. In practice it means that the "get column / row" function would often return a tile ID that was inaccessible (solid object). To fix this, I simply added half a tile to the coordinates of actors when executing the "get column / row" function (see screenshot). I only figured this out when I drew the column and row attributes over my actors and saw that the numbers were off...

merrak

  • *
  • Posts: 2620
Sounds like you found the culprit. The x,y position of an actor is always the upper left corner. But you don't need to manually add half of the tile width. The Y of self block has "Y (center) of self" in its dropdown menu options.

The documentation is a little out of date. Adding a footnote about centering sounds like a good idea.

UnrealCanine

  • Posts: 244
Sorry for the bump, but is this still up to date with Stencyl 4?

merrak

  • *
  • Posts: 2620
Sorry for the bump, but is this still up to date with Stencyl 4?

I'm using a derivative of it and haven't ran into any problems. If something comes up let me know and I'll fix it.

yoplalala

  • *
  • Posts: 1612
Found a bug ! And corrected it :)

Bug,
- you have a waypoint0, with mutiple connections,
one to waypoint1 : "connection_0_1"
one to waypoint2 : "connection_0_2"
- let's ask the path by nodes from waypoint0 to waypoint1
it will tell us that the connection is "connection_0_2"

why ?


Code: [Select]
for ( connection in currentNode.connections )
{
var tentScore:Float;

neighborNode = connection.to;

if ( neighborNode == null )
continue;

if ( closedSet.indexOf( neighborNode ) > -1 )
continue;

tentScore = currentNode.g + connection.cost;

if ( openSet.indexOf( neighborNode ) < 0 )
openSet.push( neighborNode );
else if ( tentScore >= neighborNode.g )
continue;

neighborNode.parent = currentNode;

neighborNode.parent.activeConnection = connection;

neighborNode.g = tentScore;
neighborNode.f = tentScore + costEstimate( neighborNode.r, neighborNode.c, goalRow, goalCol, graph.norm );
}


it is because of this
neighborNode.parent = currentNode;
neighborNode.parent.activeConnection = connection;

So I changed it to

neighborNode.parent = currentNode.clone();
neighborNode.parent.activeConnection = connection;

and added the function clone to GraphNode

Code: [Select]
public function clone(){
var gn = new GraphNode(r,c,name);
gn.activeConnection = activeConnection;
gn.parent = parent;
gn.connections = connections;

return gn;
}

merrak

  • *
  • Posts: 2620
Interesting. Thanks for the report; I'll update the extension.

As a side note, I really should clean up this extension. I don't think using r,c coordinates to refer to nodes was the best design choice.

yoplalala

  • *
  • Posts: 1612
Haha. I also plan to clean all my firsts extensions.  Some of them are so inneficient :)
But it's a sign we've improved in coding .

I have maybe a suggestion
- for  "AITools.autoDrawGraph("texte",true);"
you draw the  graph as if you considered the row is a tile row, and the column, a tile column.
but maybe you could add a pixel option where the row is x, and the column is y .


JeffreyDriver

  • Posts: 2260
Has anyone got quite a simple example working? Trying to get my head around it all. What I want to do is when clicking a tile, if the player can get to it, it does so.

merrak

  • *
  • Posts: 2620
Does the sample project include that example? It's been a while since I've looked at it.

JeffreyDriver

  • Posts: 2260
No, doesn't look like it. I've managed to pick it apart a little but haven't got it working properly.

http://www.stencyl.com/game/play/42283

The path only seems to set if you click the bottom-right of the screen.

EDIT: I think I've figured it out. The camera was smaller than the scene and I was running it at 2x scale. Can I get it work like that?

Thanks.


merrak

  • *
  • Posts: 2620
Pathfinding only looks at the graph. It doesn't care about the camera or the scene. The graph generator does care about the scene, though..but not the camera. I'm having a hard time understanding what your code does because of all the ellipses. Did you recently upgrade to one of the newer Stencyl builds? I've been getting ellipses too, and I think it's because of the newer Java version that is bundled.

x/y of mouse does use screen coordinates, so the screen being too small may be problematic for the mouse.

JeffreyDriver

  • Posts: 2260
Thanks again. Yeah, you were right. It was the mouse. Fixed by having an actor follow the mouse and use those XY values, but still not working correctly yet.

The ellipses are quite annoying. I noticed it started recently. I'm not on the latest build. I think I'm a couple behind.

« Last Edit: June 01, 2020, 11:21:49 pm by JeffreyDriver »


merrak

  • *
  • Posts: 2620
Something does seem odd about it. I can't seem to view your code screenshots, though. I think the resolution is too big.