Stencyl 3.4.0 is now out. Get it now!

Is simple, low-level path finding possible?

fillergames

  • Posts: 732


So enemies in my game run away from players when they get scared. This is done by using  invisible "raidus" actors that they walk and into and hide. It works fine if there's no obstacles in their path, but they'll just walk into a wall if there is anything in their way.



The red follow squares are the actors that are used to tell where the hiding spots are, but the one on the bottom causes the enemy to walk into a wall when they try to get to there.

I was thinking of doing some sort of simple pathfinding to get across, I tried the AI tools extension, but it caused a lot of lag, and I had no idea how to make it pathfind right.

« Last Edit: July 13, 2017, 08:20:07 pm by fillergames »

merrak

  • *
  • Posts: 1605
I don't know what you mean by "low level". There are simpler approaches than A* depending on how careful you want to be with obstacle placement.

The AI tool pathfinder will lag if you have a very large graph. How did you set that up? I recently updated the example project that illustrates how to get an actor to find its way out of a maze that was approximately 400 tiles or so in area.

ceosol

  • *
  • Posts: 2132
I usually create waypoints and have the actors continue to move towards a waypoint before switching to another waypoint.

fillergames

  • Posts: 732
Low level would be not really laggy.

The waypoint method might work.

fillergames

  • Posts: 732
Is it possible for the AI tools extensio determine the possible pathfinding route to a waypoint for from a limited distance only once it's needed? As enemies don't use pathfinding unless scared.

That might be my solution right there.

TheIndieStation

  • *
  • Posts: 2193
I havent use the toolswt yet, but it sounds easy enough to do that. Only calculate the path when the player is in sight.

merrak

  • *
  • Posts: 1605
It's possible, but if you're having issues with lag then that's not likely to solve that problem. Computation time is mainly a function of the graph size (if you're using the auto-graph block, then that corresponds to the size of your map).

If you're computing a path on every frame or engine tick, then that's probably the issue. It's also possible that there isn't a path at all--and that case would have to be handled.

Using waypoints is another good approach, but you still have to program the NPCs to answer an important question: Which waypoint do I run to? What you may want to do here is have the NPC search through a list of waypoints sorted from nearest to farthest, and walk toward the first waypoint it can see (use raycast to determine if an obstacle lies between it and the waypoint).

If you don't have enough waypoints then the observant player is going to notice NPCs always run away to the same locations.