AI random path issue

Hi All,
I'm new to GS and am trying to figure out an ai system for a Pac Man style maze. I worked out a system that in theory should work... I have waypoint actors set up at all intersections or corners, all with an individual ID, that when the scene starts they write their coordinates to a table with the row assigned by their ID. Then in the enemy I have a separate rule for each waypoint that when the enemy X,Y = tablewaypoint# X,Y create a random number (1, max number of possible directions) then nested rules if random number = 1 move to tablewaypoint# X,Y (the next waypoint in a whatever direction). If random number = 2 etc...
This seems to me like it should work, but I have found that the enemy actor will only move to the X,Y of random number 1.
Order of operation or the what the X,Y coordinates are seem to make no difference.
Is there a reason for this or a possible GS bug?
I hope this makes sense.

Thanks for your help.

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    It seems to work fine when I remove this but still leaves me with the problem of enemies doubling back on themselves. Any ideas to prevent this?
    Each time an enemy reaches a waypoint, have it save an additional set of x/y positions to indicate the last waypoint's position. Then, when it reaches another waypoint, check to see if the distance (e.g. magnitude or x1-x2) is at least a certain amount (and if so, save its position). Otherwise, ignore that checkpoint and keep moving the same direction.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    It makes sense and it sounds like the right setup. I can take a look at it if you like (compress your file into a .zip and send me a private message with a download link from a file-sharing service). Otherwise, you'll need to post screenshots of your rules... specifically the "possible directions" rules as I suspect something's not quite right there.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CluvCluv Member Posts: 229
    Have you tested to make sure that the random number is actually printing something other than 1? Maybe output that to text to make sure that that is working. Then, try changing your rule from = to 1 to > 1 and see if you still have the same problem.
  • 3itg3itg Member, PRO Posts: 382
    You said nested...
    Try adding a few debug statements in the important spots. Then, since each of these actions should only be taking place per actor, one time. Make sure the rule for ID#2 is in the otherwise section for ID#1, #3 should be in #2 otherwise and so on.

    If you are already using otherwise, then use the debugger to find out why your conditions aren't firing. Another good thing to try is to turn on/off related rules to see how they effect stuff.
    Let us know what you figure out.
  • Thanks for all your comments. They have all been very helpful, especially the advice to use the debugger (a very handy tool) I had never used it before but will come in very handy I think.

    So with the help of the debugger I believe I found the problem, which was something I didn't initially describe. It was a check on the last waypoint X,Y to make sure the enemy would keep moving forward and not just move back and forth between two waypoints. because my maze is all in a grid formation sometimes one of the X or Y would match the last waypoint therefore moving to the otherwise function and looping back to creating a new random#.

    It seems to work fine when I remove this but still leaves me with the problem of enemies doubling back on themselves. Any ideas to prevent this?
  • Hmmm thats an interesting Idea, but because my maze is in a grid a lot of the waypoints will be the same distance from each other... maybe I could use the same technique but with direction? i.e.. VectorToAngle? I'll give it a go and see what I come up with.
    Thanks again for your help.
Sign In or Register to comment.