Character animation in Ogre

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
lithander
Greenskin
Posts: 125
Joined: Fri Nov 09, 2007 4:46 pm
Location: Bremen, Germany
x 3
Contact:

Character animation in Ogre

Post by lithander »

Disclaimer: this is long but hopefully interesting enough to make you read! Sorry for not writing a TLDR version!

What is this post about?

Our artists want to know how they are supposed to skin the characters (setup a skeleton and assign the vertices of the mesh to one or more bones) so we can do what we want to do without running into problems. Despite being very new to Ogre I have to answer that question now...

So let me explain a bit about what we want and how I think it could be achieved in Ogre. If we take a wrong approach now it's probably hard to fix without losing a lot of work.

What we want...

Imagine a character walking. The way he moves his feet kinda defines how the characters world position needs to be adapted. And its not a constant movement. When a feet touches the ground there's friction, so the relative position between feet and ground has to remain the same. Mess up with that and the feet end up sliding.

So you can't just loop a walking animation and move the character linearly. Instead the information about how the characters world position and orientation changes has to be derived from the animation data. But as far as I've seen it the skeleton file format used by Ogre doesn't include such informations.

This becomes even more complex when you need to blend multiple animations. Like running, walking and turning animations. What we want is a system where we can arbitrary combine various skeletal animations that may or may not loop and where it's possible to change the animation weights at runtime. And based on the combination of active animations the characters world position and orientation has to be updated correctly.

How I'd do it...

My approach would be to encode character movement in the characters root bone. Let's say the characters hip would be his skeletons root. I'd add another bone to the hirarchy that might start at the ground level and connects to the characters hip. Animate the characters walk animation or whatever and then move this root bone (like the handle of a stick puppet) so the feet remain in place when they touch the ground.

Now the animators can control how the characters move in the world. When the animation loops however the character would jump to it's initial position. This is where my animation system needs to kick in and adapt the scene node so the characters position and orientation in world space remains unchanged.

All this needs to support multiple blended animations and it may not result in any noticable performance hit. Whenever one of the blended animations loops, is removed or gets it's weight changed by a noticable amount I need to detect the resulting "disruption" that would happen and counter it by adapting the scene nodes position and orientation.

How to implement it...

Each character may have multiple frame listener objects responsible for one or more active AnimationStates. The AnimationState can be advanced using the following code:

Code: Select all

float overlap = pAnimState->getTimePosition() + timeDelta - pAnimState->getLength();
if (overlap >= 0)
{
	pAnimState->setTimePosition(pAnimState->getLength());	
	m_pPuppet->StoreSpatialState();
	pAnimState->setTimePosition(0);	
	m_pPuppet->RestoreSpatialState();
	pAnimState->setTimePosition(overlap);
}
else
	pAnimState->addTime(timeDelta);		
Puppet is a wrapper object around a character entity.

It's StoreSpatialState could work like this:

Code: Select all

//update the skelleton
m_pEntity->getSkeleton()->setAnimationState(*m_pEntity->getAllAnimationStates());
//read infos from the root bone
m_StoredOrientation = m_pRootBone->getOrientation();
m_StoredPosition = m_pSceneNode->getOrientation() * m_pRootBone->getPosition();
And RestoreSpatialState would work like this...

Code: Select all

//update the skeleton
m_pEntity->getSkeleton()->setAnimationState(*m_pEntity->getAllAnimationStates());
//revert the change
Quaternion newOrientation = m_pSceneNode->getOrientation() * m_StoredOrientation * m_pRootBone->getOrientation().Inverse();
m_pSceneNode->setOrientation(newOrientation);
Vector3 newPosition = m_pSceneNode->getPosition() + m_StoredPosition - m_pSceneNode->getOrientation() * m_pRootBone->getPosition();
m_pSceneNode->setPosition(newPosition);
Does that approach make sense? Any comments?

/edit: some clarifications
gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore
x 3

Post by gamedboy »

I am also using character-based approach.

In short it allow the artist to control a character movement in the game.

I agree that normal walk on the spot animation can prob do everything character-based animation can do. However for animations like rolling jump, sliding dodge; It prob involve writing separate fuctions for them to achieve realist result. Using character-based, it prob just involve calling animation->play("rolling-jump"). And since the whole movement and animation is now artist controlled, it would need less polishing to get the desired result.

It allow artist to control certain gameplay element like firing arc, turning rate. However it is also not perfect, for every area artists wanted to control, they got to animate it.

I had currently integrated physX character controller with it, so far the result is pretty good, with collision detection, auto stepping. Now I am trying to test AI using this.
User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
x 8
Contact:

Same

Post by fassihi »

We have thought about the exact same problem. For the first part we are using the same solution, defining a new bone called "center" which stays underneath the character and then aligning the scene node with this bone.
However we haven't done anything for blending yet.

Have you tested your code for blending and is everything working fine?
User avatar
SpaceDude
Bronze Sponsor
Bronze Sponsor
Posts: 822
Joined: Thu Feb 02, 2006 1:49 pm
Location: Nottingham, UK
x 3
Contact:

Post by SpaceDude »

Just a warning on making player movement based on character animation: I tried doing this for a game I was developing with a friend a couple of years ago. My friend was is in charge of modelling and animation while I did the programming. We ran into a lot of trouble, the artist needs to be very precise when creating the animations in order for things to work smoothly. You will need to make sure your artist fully understands the implications of this. Although it sounds like a cool concept it does add a whole load of complications. You will end up needing to compromise: a) The artist will have restrictions when creating the animations in order to get realistic movement, b) You may have to sacrifice getting the exact movement you want in favour of good looking animation.

But if you decide to go ahead anyway, you can get the position and orientation of individual bones in a skeleton. So if you want to base movement on animation the easiest way to do it would be to get the difference in position/orientation of the foot that is in contact with the ground between each animation frame. Let's ignore orientation for a second and concentrate just on position. It could be done as follows:

- Get position of foot (A)
- Apply changes to animation
- Get position of foot (B)
- Displace character by vector: A - B
User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
x 8
Contact:

Nice

Post by fassihi »

Thanks space dude, this is a clever idea. This way the final translation and rotation can be found out.

In some cases there has to be such animations and some game genres would be impossible without this, for example : God of War or the new Beowulf, they have these mini games, in the mini games the character climbs on the monsters and can literally do any kind of movements, now if all these animations are generated "in-place" and we want to position the character correct in the engine, this would be a nightmare.

Unless there can be a smooth method for exporting the path that shows how the character should translate and rotate and moving the character scene node on that path !?
HexDump
Halfling
Posts: 75
Joined: Sun Jul 25, 2004 12:50 am

Post by HexDump »

Sorry for that, but can´t see what is all about :(. Could anybody explain why is ths movement based on animation? I´m a bit lost.

Thanks in advance,
HexDump.
User avatar
SpaceDude
Bronze Sponsor
Bronze Sponsor
Posts: 822
Joined: Thu Feb 02, 2006 1:49 pm
Location: Nottingham, UK
x 3
Contact:

Post by SpaceDude »

I'm afraid I haven't played God of War or Beowulf so I'm not quite sure what you mean.

The main trouble I had is that even with just a simple walking animation the player movement didn't look smooth. This could be blamed in part on the animation though :). The other thing is that you need some way to determine which foot is in contact with the ground, and you may end up at times where both feet are in contact with the ground but moving in different directions. What do you do then? Maybe take the average movement of both feet, you'll get some sliding then.

I'm not saying you shouldn't do it, just warning that in my experience it is quite difficult to get it to work nicely.
User avatar
lithander
Greenskin
Posts: 125
Joined: Fri Nov 09, 2007 4:46 pm
Location: Bremen, Germany
x 3
Contact:

Post by lithander »

Sorry for that, but can´t see what is all about Sad. Could anybody explain why is ths movement based on animation? I´m a bit lost.
Let's say we have a character with a walk animation. The animation is set up in way where only the leg bones move but the root bone stays fixed. Now, if we don't change the position of our character entity in the scene then the characters feet will slide over the floor but not move his body forward.
To do that the animation could move the root bone too and it would look okay at first glance. But the character would run out of it's bounding box and once we loop the animation he would jump back to its old position.

So I was looking for an approach where I could just blend animations and the character entity is moved and rotated so it all "looks" right in the scene. How this could be done is more or less what is discussed here!

By the way: my above suggestion is not what we currently use as I got some valuable input on the topic in this threat: http://www.ogre3d.org/phpBB2/viewtopic.php?p=261048
Last edited by lithander on Tue Dec 18, 2007 3:06 pm, edited 2 times in total.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Post by nikki »

SpaceDude wrote:I'm afraid I haven't played God of War or Beowulf so I'm not quite sure what you mean.
You can check out this video from 'Shadow Of The Colossus'. In that game, you have to climb on the monsters, as if they're landscapes, and the monsters are animated. I think that's what he means. Watch it here:-
Link
User avatar
SpaceDude
Bronze Sponsor
Bronze Sponsor
Posts: 822
Joined: Thu Feb 02, 2006 1:49 pm
Location: Nottingham, UK
x 3
Contact:

Post by SpaceDude »

nikki wrote:You can check out this video from 'Shadow Of The Colossus'. In that game, you have to climb on the monsters, as if they're landscapes, and the monsters are animated. I think that's what he means. Watch it here:-
Link
Hey that looks damn cool! I spend too much time programming and not enough time playing :( missing out on all these nice games. Anyway, what I see here isn't the same as what was described in the original post.

From the video I see that the small character's position needs to be fixed relative to the limb of the big character he is currently climbing on. This is a separate issue that I guess would be solved in a similar way.

I'm not sure which you were intending to describe lithander?
gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore
x 3

Post by gamedboy »

Have you tested your code for blending and is everything working fine?
yup blending work fine, My animationController support unlimited normal animations and 1 displacementAnimation.

Only the displacementAnimation would move the sceneNode, the rest just uses Ogre default animation blending.
- Get position of foot (A)
- Apply changes to animation
- Get position of foot (B)
- Displace character by vector: A - B
Another way is to get the position of center node in last frame and current frame, get the difference and apply to the sceneNode.

So far the main advantage of character-based animation is the ease of implementing character actions. If I need a roll action, I just call character->playAnimation("roll"), and everything would be handled for me. Comparing to on the spot animation, I save a lot of time tweaking to make the animation look correct.

There is also some severe disadvantages to character-based animation.
It is extremely difficult to move the character to an exact location without any visual artifact. Because of this network game would be rather challenging.

It added another layer of performance overhead.

It also reduce the opportunities for hardware animation.

The bottom line is character-based animation would allow very realistic animations in a fraction of time normal animation took. However for some projects it may not worth spending the effort implementing it.
User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
x 8
Contact:

Post by fassihi »

gamedboy,

Could you elaborate this problem a little more please:
It is extremely difficult to move the character to an exact location without any visual artifact. Because of this network game would be rather challenging.
gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore
x 3

Post by gamedboy »

In normal animation when I want to move from point A to B, I just interpolate btw the points and move the sceneNode. I can easily control the character in code to move it to point B exactly.

To use character-based animation(CBA) effectively, I can only call
character->playAnimation("walkforward")
character->stopAnimation()

Where the character ended up at really depend on the animation played and the duration.

A simple solution is to slide the character abit in code to make sure it land correctly at B, however it would defeat the purpose, as it would cause sliding as per normal animation.

Another solution, is to keep track of the velocity and distance moved by each animation, and choose the right combination of animations to move to point B. This would also not land the character precisely at point B.

In most network games, a measure of interpolation and extrapolation is used. Using CBA, interpolation and extrapolation is already hardcoded in the artist animation. Smoothing of character position would be challenging without sliding the character.
User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
x 8
Contact:

Thanks

Post by fassihi »

Thanks for describing it.

Yes it seems like in order to have complete control over such issues a complex animation system is needed that would manage the Animation Local space with the game world global space somehow. Something that we do not currently have and might need a new way of looking at how animation is done. The least would be exporting meta data with each animation. But a robust pipeline is necessary.

Does anyone have any specific information regarding how these issues are tackled in major game titles? Any articles?
User avatar
lithander
Greenskin
Posts: 125
Joined: Fri Nov 09, 2007 4:46 pm
Location: Bremen, Germany
x 3
Contact:

Post by lithander »

To use character-based animation(CBA) effectively, I can only call
character->playAnimation("walkforward")
character->stopAnimation()

Where the character ended up at really depends on the animation played and the duration.
Why do you limit yourself to one displacementAnimation? If you wouldn't do that you could blend animations so your character ends where you want it to end.

Basic Example: Lets say you have 10m to walk forward. If you have two animation cycles - one with long steps, covering 3m and the other covering only 1.5m (shorter steps). By just blending between the two you could make the character stop at exactly 10m after 4 cycles.

You just have to find the right blendweights:

10m = 4 * x * 3m + 4 * (1-x) * 1.5m
10m = 12m * x + 6m - 6m * x
4m = 12m * x - 6m * x
4m = x * 6m
x = 2/3

So the long walk cycle needs to be weighted with 0.666 and the short with 0.333 and 4 walk cycles will move the character exactly 10m.

@fassihi: I've never seen an article about that. And I guess thats because every game has different requirements and if you need to make some animation-based character movement, developers tend to find a very specific solution.
gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore
x 3

Post by gamedboy »

For movement in a straight line it is easy. My current method is to move the 3m animation 3.33 cycles, then stop displacement and transit the animation to neutral pose.

The tricky part is when you want to, say strafe your character 15 degree to the right for 10 meters; or 85 degree for 0.1m.

one displacementAnimation is for practical reason, my artists already adjusted the displacement to be correct for the animation, by blending 2 the final result may not be what they wanted.
JeDi
Gnome
Posts: 351
Joined: Thu Oct 21, 2004 1:34 pm
Location: Diepenbeek, Belgium
x 3
Contact:

Post by JeDi »

Why not just use the root node animation as world displacement in stead of actual bone animation each frame? The character would stay in its bounding box, and the exact movement is still in the hands of the artist. I don't see any issues in blending or looping animations.

The remark about correct positioning is correct. But this can be solved by using for example a motion graph, where you can search the correct animation(s) to use to get to the position.

I'm going to experiment with this a bit, though it won't be very productively as I broke my right hand.

Greetz,
JeDi
User avatar
Sycle
Halfling
Posts: 45
Joined: Sun Jun 11, 2006 8:21 am
Location: Sydney

Post by Sycle »

I'm an animator, at work it's been all character animation driven since the PS2.

The more common method I've seen is to have an independently movable root node (sometimes kept linear due to technical requirements) that is set up to sit under the hips of the character. The character is animated normally (moving forwards in the 3D scene) and in engine, the game extracts the movement of the root node and uses that to reposition the entity. (while throwing away the root node's actual animation track)

I've seen a few variants on this, but they're all pretty similar from an animation workflow point of view. I also can't think of a situation where a character has been required to move exactly 10m forwards using arbitrary animations. Moving to a specific point in the world is a lot more common, and both systems work equally well for that.

gamedboy - I'm not sure I get what you mean about the strafing, if you have a loop of "walk forwards", "walk 45 degrees to the left" and "walk left" and control the blending, as long as the leg cycles are in sync you can get all the angles in between pretty well.
gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore
x 3

Post by gamedboy »

JeDi - yup we been using root node animation to move the character around as discussed in
http://www.ogre3d.org/phpBB2/viewtopic.php?p=261048
gamedboy - I'm not sure I get what you mean about the strafing, if you have a loop of "walk forwards", "walk 45 degrees to the left" and "walk left" and control the blending, as long as the leg cycles are in sync you can get all the angles in between pretty well.
I am not an animator, is it easy to create animations that can blend well together? Or is it more feastible to create a tool for my animators to tweak the blending?

My attempts at blending animations which uses the same bones ended up looking as the character bones r dislocated.
The more common method I've seen is to have an independently movable root node (sometimes kept linear due to technical requirements) that is set up to sit under the hips of the character. The character is animated normally (moving forwards in the 3D scene) and in engine, the game extracts the movement of the root node and uses that to reposition the entity. (while throwing away the root node's actual animation track)
Is there any reason to setup the root node at the hip, my current implementation is set at the feet of the character.

Thanks.
JeDi
Gnome
Posts: 351
Joined: Thu Oct 21, 2004 1:34 pm
Location: Diepenbeek, Belgium
x 3
Contact:

Post by JeDi »

I just read that other post. Good to know this is actually going to work :)

About the root joint at the position of the feet. Why do artists do that sometimes? A lot of models I've seen have their root joint between the feet, as parent of the hip joint. Is this purely so the model can be placed on the ground easily?

Greetz,
JeDi
User avatar
Sycle
Halfling
Posts: 45
Joined: Sun Jun 11, 2006 8:21 am
Location: Sydney

Post by Sycle »

gamedboy - the rule of thumb with blending two animations is as long as the limbs are vaguely moving the same way, the blended result should look sensible.

If you have the arms raised in animation A and solving a rubics cube between their legs in animation B, blending the two will be unpredictable. But if animation A is a walk loop starting with left foot fully forwards, and animation B is a 45 degree strafing loop starting with left foot fully forwards, a 50:50 blend will probably give you a passable impression of strafing at 22 1/2 degrees. (of course, averaging the position of the root node will give you movement in the correct direction, but the distance it travels will need to be normalised)

gamedboy, JeDi - whoops! Yup, I meant that the root bone was on the ground. (but directly below the hips, ie it moves where the character moves)

Generally the root node remains at the ground plane except for climbing animations or things that will change the characters elevation in game.
gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore
x 3

Post by gamedboy »

Sycle - Thanks for the tip.

I got a simple viewer up to test out the blending, hope it will be useful.
http://www.ogre3d.org/phpBB2/viewtopic. ... fa316f8eee
User avatar
koirat
Orc
Posts: 446
Joined: Mon Feb 25, 2008 7:56 pm
x 13

Re:

Post by koirat »

Sycle wrote:I'm an animator, at work it's been all character animation driven since the PS2.

The more common method I've seen is to have an independently movable root node (sometimes kept linear due to technical requirements) that is set up to sit under the hips of the character. The character is animated normally (moving forwards in the 3D scene) and in engine, the game extracts the movement of the root node and uses that to reposition the entity. (while throwing away the root node's actual animation track)
"character animation driven" <-- does it mean that models are animated in place ??
Or movement is calculated from animation ??

I have seen some clips with this second approach in youtube, as i remember correctly it was Half Life 2 model, but i do not know if it was original or some mod-er stuff.

Do you know what is used in Crysis or Halo 2 ??. In place or movable animation ??
This is a block of text that can be added to posts you make. There is a 255 character limit.
User avatar
fassihi
Goblin
Posts: 215
Joined: Sat Sep 16, 2006 6:51 am
x 8
Contact:

Re: Character animation in Ogre

Post by fassihi »

Moving (not in place) animations probably since it would be possible to generate any specific motions this way, the artist would do that. If in place animations are used, then the engine would need to decide about the movement and this is not always trivial to be modeled and handled by the engine. An example would be a change of pace in a jog animation.
User avatar
koirat
Orc
Posts: 446
Joined: Mon Feb 25, 2008 7:56 pm
x 13

Re: Character animation in Ogre

Post by koirat »

So what about blending animations??
When animating not in place are thy just masking off root bone ??
So the skeleton is in the same place ?? Even when in animation it's position is changing ??
This is a block of text that can be added to posts you make. There is a 255 character limit.
Post Reply