AI random path issue
johnylawless@gmail.com
Member Posts: 2
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.
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
-
tatiang Posts: 11,949
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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.
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?
Thanks again for your help.