Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :)

share|improve this question
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. – Setrio Dec 20 '12 at 12:28

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.