Skip to main content
gamedev.net
🔒 Locked

Animation Algorithm ?

Started by BUnzaga Mar 23, 2011 at 1:36 PM 1 replies 750+ views
Original Post
BUnzaga
BUnzaga
I'm working on a shooter style game, and I am wondering what others have done to tackle the problem of what animation to play at any given time.

Like if the user is running forward, jumping, shooting, and taking a hit all at almost the same time, how do I figure out what animation should be played?

I don't really like the idea of a long massive iteration to check constantly, so I figure there has to be a better way out there. I was thinking of trying to use a forward chaining inference engine, but I am having a little trouble understanding how to implement it, and think it might be a bit of over kill.

Some common examples... running forward and strafing, while shooting, or running and jumping, strafing and jumping, running and shooting, etc. There has to be a way to determine exactly what animation to play at any given time.
zerothrillz
zerothrillz
If you wanted all of those behaviors animated simultaneously you have two options: create artwork for all of the possible combinations (a lot of work) or break the player into multiple layered sprites. Usually, torso and legs or arms if you want different gun types.

The way I do it in my small game is when a situation happens that warrants a change in animation, I call animation_timer.changeClip(new_animation_index) or animation_timer.playClipOnce(new_animation_index). Granted, I'm using only a single sprite and not animation the player separately but the idea would be the same:

For example, I'd call


leg_animation_timer.setClip(WALK_CLIP_INDEX)
torso_animation_timer.setClip(IDLE_CLIP_INDEX)
//...
if(shoot_gun) {
torso_animation_timer.playClipOnce(SHOOT_CLIP_INDEX)
}


If the animation is to be interrupted, you can also create transition animations that blend going from one animation to another. For example, going from walking to getting hurt or going from shooting to getting hurt. The getting hurt animation could can be the same for both beginning states. Putting a 1 or 2 transition frames in can ease any jerkiness.
Buckeye
Buckeye
You'll need to keep track of the current state of each character, assuming that a transition to a new state depends on the current state. That is, jumping-then-hit will result in something different than idle-then-hit. You might want to consider a simple state engine.

The general loop sequence might be something like:

1. get user input
2. do collision detection - including determination whether a character runs into a wall, gets hit by a bullet, catches sight of an enemy, etc. Set flags or other info for each character to be evaluated (events, conditions, etc..)
3. iterate through each character, updating the state, taking into account the current state and the new set of flags for this frame.
4. setup the animation/render-info for the current state
4. render

You'll need to sit down with a pencil and paper and enumerate the states you want the character to have. Then, for each state, determine how that state should change (transition) in response to inputs, singly or in combination.

As zerothrillz mentions, you may want different parts of the character to have their own states - a character can run (lower-body) and aim (upper-body) at the same time.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.