Jump to content
  • Advertisement

Archived

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

exodus7

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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)

Share this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!