Predefined AI patterns
Hey ALL, I'm at the stage now were I can start giving my enemy object(s) some "intelligence". I want to start simple by using pre-defined patterns but I have no idea on were to start. My idea is to have the "pattern" in a pre-defined script that can be loaded and parsed at load time. As simple example say a door guard moves from left to right and then back again. Any ideas?. Thoughts/Suggestions appreciated. MAMEman.
By "pattern" I think you mean something like a "patrol path" and not a software design pattern, right? Assuming that's the case.
Patrol paths are easy. You just have an array/linked-list/vector/whatever of destination points. Then you have either a state/behavior/whatever is appropriate for your AI that follows that path. It's pretty simple:
1) pathfind to next point
2) locomote to next point
3) OnMoveDone give the state/behavior a message to that effect
4) pop the current destination from the waypoints list
5) goto 1 until waypoint list is empty
If it's a looping path insert an additional step:
1) pathfind to next point
2) locomote to next point
3) OnMoveDone give the state/behavior a message to that effect
4a) pop the current destination from the waypoints list
4b) push that same destination to the end of the waypoints list
5) goto 1 until waypoint list is empty (which never happens in this case because of 4b. so you're in this behavior until triggered out of it by another state: aggro, death, another behavior is triggered, whatever)
Before you implement this however you should already have an AI that is capable of moving to a destination. The "follow waypoint path" state/behavior is a simple extension of that. If you don't have that yet, wait on this behavior because implementing a simple "go to destination" state/behavior will be enough work to occupy you for a while (assuming that AI is unfamilliar territory).
-me
Patrol paths are easy. You just have an array/linked-list/vector/whatever of destination points. Then you have either a state/behavior/whatever is appropriate for your AI that follows that path. It's pretty simple:
1) pathfind to next point
2) locomote to next point
3) OnMoveDone give the state/behavior a message to that effect
4) pop the current destination from the waypoints list
5) goto 1 until waypoint list is empty
If it's a looping path insert an additional step:
1) pathfind to next point
2) locomote to next point
3) OnMoveDone give the state/behavior a message to that effect
4a) pop the current destination from the waypoints list
4b) push that same destination to the end of the waypoints list
5) goto 1 until waypoint list is empty (which never happens in this case because of 4b. so you're in this behavior until triggered out of it by another state: aggro, death, another behavior is triggered, whatever)
Before you implement this however you should already have an AI that is capable of moving to a destination. The "follow waypoint path" state/behavior is a simple extension of that. If you don't have that yet, wait on this behavior because implementing a simple "go to destination" state/behavior will be enough work to occupy you for a while (assuming that AI is unfamilliar territory).
-me
Hi Palidine,
Yes I'm a noobie to AI and yes I do mean "patrol path" ;). I was thinking along the same lines actually. I got to the point of having a list of vectors (or waypoints as you call them ;)) that my character would move along, but wasn't sure about what to do at the various waypoints. But I notice that you mentioned state changes. Oddly enough my character has a FSM, so presumably as you mentioned, I could just change the state once that character has reached a point. In my case just change the direction of the character or whatever.
Thanks for the feedback.
MAMEman,
Yes I'm a noobie to AI and yes I do mean "patrol path" ;). I was thinking along the same lines actually. I got to the point of having a list of vectors (or waypoints as you call them ;)) that my character would move along, but wasn't sure about what to do at the various waypoints. But I notice that you mentioned state changes. Oddly enough my character has a FSM, so presumably as you mentioned, I could just change the state once that character has reached a point. In my case just change the direction of the character or whatever.
Thanks for the feedback.
MAMEman,
"Waypoints" are locations, not directions; they specify the path at an abstract level and movement between them isn't necessarily straight; the agent needs a generic pathfinding system to find an appropriate step by step path. Waypoint therefore specify salient points or deviations from the shortest or most obvious path between more important waypoints.
For example, suppose a patrol is meant to follow the streets of Manhattan Island and circle around the slice between 110th and 125th Street, clockwise. (Disclaimer: I'm making this up from Google Maps, I've never been there.)
The first two waypoints could be the intersections of 125th street and Riverside Drive (P1) and the short A new street (P3).
But a pathfinder would choose as the shortest path, in both directions the oblique St Nicholas Avenue and the last part of 110th Street: there must be another waypoint P2 between P1 and P3, e.g.the end of the Triborough Bridge, to patrol the whole 125th Street then 1st Ave, and a fourth one, P4 between P3 and P1, possibly the intersection of 110th Street West and Riverside Drive, to similarly follow 110th Street and some branch of Riverside Drive on the return leg.
Then if there are special points of interest one can add even more waypoints: for example, to replace the middle part of 110th Street along Central park with a detour, the two northernmost corners of Central Park can be inserted as waypoints between P3 and P4 and a point of interest (somewhere inside Central Park, down 7th or 5th Avenue, etc.) can be inserted between the two corners without disturbing the patrol segments along the eastern and western portions of 110th Street.
What's important is that specifying movement explicitly through thousands of obstacles would be madly complex and inflexible, while an implicit definition requires only a few points, is very natural, leaves the hard work to the computer, leverages the existing terrain model and easily adopts its dynamic modifications, and can be adapted to moving obstacles, formation pathfinding, etc..
For example, suppose a patrol is meant to follow the streets of Manhattan Island and circle around the slice between 110th and 125th Street, clockwise. (Disclaimer: I'm making this up from Google Maps, I've never been there.)
The first two waypoints could be the intersections of 125th street and Riverside Drive (P1) and the short A new street (P3).
But a pathfinder would choose as the shortest path, in both directions the oblique St Nicholas Avenue and the last part of 110th Street: there must be another waypoint P2 between P1 and P3, e.g.the end of the Triborough Bridge, to patrol the whole 125th Street then 1st Ave, and a fourth one, P4 between P3 and P1, possibly the intersection of 110th Street West and Riverside Drive, to similarly follow 110th Street and some branch of Riverside Drive on the return leg.
Then if there are special points of interest one can add even more waypoints: for example, to replace the middle part of 110th Street along Central park with a detour, the two northernmost corners of Central Park can be inserted as waypoints between P3 and P4 and a point of interest (somewhere inside Central Park, down 7th or 5th Avenue, etc.) can be inserted between the two corners without disturbing the patrol segments along the eastern and western portions of 110th Street.
What's important is that specifying movement explicitly through thousands of obstacles would be madly complex and inflexible, while an implicit definition requires only a few points, is very natural, leaves the hard work to the computer, leverages the existing terrain model and easily adopts its dynamic modifications, and can be adapted to moving obstacles, formation pathfinding, etc..
Omae Wa Mou Shindeiru
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement