Path Patrol

Started by
2 comments, last by exodus7 20 years, 1 month ago
Hi I''m currently working on a 3D game and I''m trying to improve the AI of my enemy character. I want the character to patrol an area on the map. Here is what I have: 5 points defined, and I''m currently using a switch statement, so that when the character reaches one of the defined points it changes position (i.e. turns left). There must be a better way of doing this, any suggestions? I was looking at A* but that finds the fastest path and not necessarily a defined path.
there is only one way
Advertisement
you could use a queue of points for the ai to visit, and when you pop a point off the front of the list to go to, you could pop it onto the back of the list so that it will be a non stop cycle(circular)
Use a circular linked list, with each point having a pointer to the next point in the list, and the last point having a pointer back to the first point.

Keep a current pointer to the next point in the patrol path you want to visit, then each frame move towards the current point, test how far away you are from the current point, and if close enough (say closer than the radius of the agent), query the current node for the next node in the list. Something like this:

point3 dir_vec = next_point->pos - cur_pos;cur_pos += dir_vec.normalize() * velocity;float distance = (next_point->pos - cur_pos).length();if (distance < radius){   next_point = next_point->next;}


Peace
Thanks Guys I''ll give that a shot.
there is only one way

This topic is closed to new replies.

Advertisement