2
\$\begingroup\$

I have started working on the AI for a game, but am confused how I should handle animations. I will be using a Behavior Tree for AI behavior and Cocos2D for my game engine.

Should my "PlayAnimationWalk" just be another node in the tree?

Something similar to this: [Approach Player] - Play Walk animation - Move Towards player - Stop Walk animation

Or should the node just update an AnimationState in the blackboard and have some type of animation handler/component reference this for which animation should be playing?

This has been driving me nuts :)

\$\endgroup\$
1
  • \$\begingroup\$ If you can separate behaviour from animations (or any other component), go that way. At least is what I try to do on my games. \$\endgroup\$ Dec 20, 2012 at 12:28

1 Answer 1

1
\$\begingroup\$

While it is, of course, possible to implement animations within an AI architecture, it would be a poor methodology for a number of reasons.

One such reason would be an agent that chooses to walk but cannot for some reason. Another reason would be needless complexity (many decisions would have to implement an exact-copy of an animation node because they all result in the same sort of behavior). Most importantly, however, is that your pathfinding will not be handled in the behavior tree, and the pathfinding algorithm is what will actually implement agent movement. Remember that the AI is only meant as a means of decision making, not implementing those decisions in the world.

A much more appropriate solution would be to tie the walking animation to the method that adds velocity to the character, which would be the pathfinding algorithm. This would implement the walking animation, or could implement a different animation for a different form of movement (running, crawling, teleporting, flying). It would be able to handle obstruction, difficulty in determining a path, and more all of which should interrupt any walking animation occurring. And it would simplify your behavior tree significantly, which is incredibly important for readability and debugging.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .