Fastest approach to having multiple AI objects detect and move along a given path?
I'm working on a game right now where I'm going to have paths dynamically built by the user for multiple AI objects to "walk" along. I'll be detecting/redrawing the path only on user input but I'm still debating over the fastest possible method to update the movement of many AI objects "walking" along/up/down the given path. Think for exampl开发者_如何转开发e of pac man, but the level is dynamic. Right now I'm leaning toward building the enemies in a linked list of final classes and looping through the linked list calling a function in each of the AI objects to plot the next move along the path. Not sure if this is the best approach, looking for ideas. :) Thanks!
It sounds like you have a bunch of instances following the same path; if so, you might be well-served to calculate the path from the furthest object, and then re-use the results of that calculation for all the closer instances. Essentially, have a PathMemoizer that has a pathFrom(myLocation : Location) : List (or whatever). Calculate the furthest path once and then have everyone call:
if(pathMemoizer.pathFrom(this.myLocation() ) == null) {
pathMemoizer.expensivePathCalculation(this.myLocation());
}
mySteps = pathMemoizer.pathFrom(this.myLocation());
精彩评论