Artificial Intelligence Tools Extension (Beta Release 8)

merrak

  • *
  • Posts: 2016
To draw a path (I'm assuming you mean a path computed using the pathfinding tool?), then all you need to do is loop through the list that is returned. Use the "as list of nodes" option. Each item in the returned list is a sublist with data for the node's position, name, and cost. Entry 0 and 1 will be the row, col coordinates of the node respectively.

Here's an example that will a dotted line along the path.

Code: [Select]
(Drawing event)
Set fill color to (color)
Transform to screen coordinates
For each item in (returned path)
    Fill circle of radius 3 centered at x: ((get entry #1 from item) + .5)*tile width    y: (get entry #0 from item) + .5)*tile height
End For

I'll need clarification on what you mean by connecting the tiles. Did one of the blocks cause a null error? If so, for what platform? Make sure you're using the latest release (Beta Release 7). There was a platform-dependent error that was reported and fixed.

AdamJ

  • Posts: 17
I've hit a little snag while using this (awesome) extension.  I created a scene behavior that creates a graph and then culls nodes out based on collision meshes of static actors; environment art that need to be avoided (basically a forest).  Then I tried to add an actor behavior to my actors so they'd use that graph to chart their course through the forest.  As I discovered, though, the graph isn't really an attribute and can't be accessed by the actors. 

So what's the best way to approach this scenario?  It seemed wasteful for each actor to generate their own copy of the graph, but maybe that's what I'm supposed to do?  Or is there a way to encapsulate or "attributify" the graph from the scene behavior so the actors can see it?

Many thanks to anyone for any guidance, and thanks to Merrak for the great extension. Thumbs up.

UPDATE: I'M AN IDIOT.  My graph is named "navmesh".  My actors were trying to chart a path on "navmash". Thus the latest example of wrestling with a problem for 2 or 3 hours and figuring it out 5 minutes after asking for help.

« Last Edit: May 21, 2017, 05:30:14 am by AdamJ »
Chickadee Games : www.chickadeegames.com

merrak

  • *
  • Posts: 2016
Sounds like you answered your own question ;)

FYI, the graph can be exported to a list attribute, but you can't use the resulting list to run any graph-based calculations (like pathfinding).

yoplalala

  • *
  • Posts: 1461
In Build 9828, AI Tools don't work anymore because of layers.

Must have to do with https://github.com/Stencyl/stencyl-engine/commit/7f340651b4fabd036f1a0627a42335b46381ec20

You can do something like this
#if (openfl <= "6.0") r, c #else  engine.getLayerById(-1) #end

« Last Edit: March 28, 2018, 01:21:39 pm by yoplalala »

merrak

  • *
  • Posts: 2016
Thanks for the notice. I guess something changed between Build 9751 (what I'm using) and 9828. I'll get an updated version up.

SirCrocketz

  • *
  • Posts: 17
Hey merrak! Just curious if you have an eta for the update on your extension. I use it pretty extensively in my current project :)

Also, Is there any kind of smoothing built in? Or know of an easy way to achieve smoothing the path results?

merrak

  • *
  • Posts: 2016
Should be updated now :)

Check 'Beta Release 8' on archives page if the main link hasn't yet updated.

Also, Is there any kind of smoothing built in? Or know of an easy way to achieve smoothing the path results?

I'm not sure what you mean by smoothing the path results. Did you see the 'merge path' block?

Quote
Optimizes a list of nodes. mergePath searches for collinear nodes, eliminates interior nodes, and preserves only the endpoints.

SirCrocketz

  • *
  • Posts: 17
Awesome! I'll download it right away! Thanks so much for the quick response :)

This image explains what I mean by smoothing (may be incorrect term). http://i.imgur.com/6UIRisc.png
I'll play around a bit to see if I can figure it out. Thanks again!

merrak

  • *
  • Posts: 2016
There isn't anything provided out-of-the-box that will produce the image on the right. The merge path function will get you partway there by eliminating all of the nodes except where the direction changes. One thing you could do to further optimize the path is search through the nodes that remain after merge path and see if any can be skipped. Something like this:

Code: [Select]
1. path = (Compute the path from Point A to Point B)
2. path = (Use mergePath to optimize the path)
3. Loop through each node n in path, starting from Point B and working backward to A
    3A. If no obstacle exists between Point A and node n then delete all nodes in the path
        from the node after Point A to the node just before n. Exit loop
    3B. Otherwise, continue

SirCrocketz

  • *
  • Posts: 17
Hey Merrak!

Quick question. If there should be two paths of equal cost, is there a way to return both of them? I'm trying to randomize my pathfinding a little bit.

merrak

  • *
  • Posts: 2016
Hey Merrak!

Quick question. If there should be two paths of equal cost, is there a way to return both of them? I'm trying to randomize my pathfinding a little bit.

You'd have to modify the algorithm. The principle sounds simple enough. (See https://stackoverflow.com/questions/10738478/how-to-find-all-the-shortest-paths-by-using-a-algorithm). It's been a while since I've looked at the A* code, but I have a feeling making the change would necessitate some reworking of how the code is organized... placing this problem neatly into the "simple in theory, tedious in application" category.

In certain applications, it'd be easier to just add some variation to the edge costs. For example, in my game I'm considering enemy actors pursuing the player. Adding variation to the edge costs would result in the enemy actors not necessarily taking the most optimal path, but would still take a "good" path. That sort of behavior seems more realistic to me. People and animals make assumptions and make mistakes. Not sure what specific problem you're trying to solve--just wanted to throw the idea out there.