#### Archived

This topic is now archived and is closed to further replies.

# Path Patrol

This topic is 5404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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)

##### Share on other sites
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

##### Share on other sites
Thanks Guys I''ll give that a shot.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013608
×