A common avatar class for Irrlicht

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

A common avatar class for Irrlicht

Post by keless »

I'm not there yet with IrrlichtRPG, but I have a system that I want to create which will be useful for anyone in Irrlicht who wants to use it. Basically the idea of an Avatar is an animated model that has different states. Now, Irrlicht gives us the ability to load in the mesh/animation/textures and even tell the renderer what animation state to draw the model in, but it has no logic as to which state models can be in and how do go from one to another. My idea (which has already been done in proffessional games, just not robustly and not in irrlicht) is to create a nice class which loads in not only an animated model, but also an XML (plain text or compiled) data file that expresses the FSM of an avatar. It has a function bool HandleCommand(char* cmd, bool forceCmd) which allows you to give any avatar a command, and if it knows how to respond to it and is able to from its current state, will do so and return true. If it doesnt handle that command it will simply ignore it and return false.

This will require creating an XML format for describing states and commands in relation to animations. It should describe default animation states, allow animations that loop, and animations that when finished will go back to the current default animation. This should also allow animation speed as a parameter (such that a slow kick state can be defined using the same animation with a slower speed than a normal kick), as well as loop duration. It should also keep in mind an 'override' parameter in the HandleCommand() function where you set the current state no matter where the FSM is currently at. Eventually a graphic editor would be helpful, but is not needed to begin with.

The ultimate benefit of this is that avatar's animation programming is made simple-- you now only need to think about high level commands ("kick", "sit", "hurt1", "die") . You can share models with their FSM data between projects, and if they dont support specific commands your project desires, you can add them in. Note that this does NOT contain any information about collision, high-level AI, or movement in your world. You have to write more code around this class to incorperate that sort of stuff, but this will allow you to do something like the following:

Code: Select all

onEvent(user pressed walk) {
 if( m_Avatar->HandleCommand("walkForward") ) {
  m_velocity += m_facing * speed;
 }
}
The power of the code above is that the logic of 'can you walk forward in your current state' is taken care of by the Avatar class. So, if your character was in the 'stunned' animation, it would fail to walk forward. Whats more; because the logic is in a file that your animator creates, he can change character animation states without significant code changes. As anyone who's done animation programming can tell you; its a lot of ugly code that has to be modified any time the designer want to make a change, and its painful.


So, to recap:
* makes avatars share-able across projects
* simplifies animation programming
* reduces re-compile time on avatar modification

As for when this will happen: I'll be getting to this fairly soon in IrrlichtRPG, but not in the next 3-4 weeks. If someone else thinks they'd like to take a shot at this in that time, I'd be happy to review/help and then modify it when I begin implementing in IRPG.
a screen cap is worth 0x100000 DWORDS
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

Just a newbies thought for you.
When you code for the movement...(walk, run, sit, walkBackward, stand), couldn't you use the keyboard and mouse commands to activate them?
if KEY KEY B isDown (walk) (or however you would code that)
I like the idea of a class written for this. :)

Oh, and while I have your attention...when are you going to finish your game engine tutorial??
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

which tutorial? the ones at http://www.technomagicum.net/projects/vgp/ ? Those were written when I was paid to write them for a class, and since its not my job any more (and since I've learned a lot more since then) it hasnt been worth it to me to continue them. Instead, I make sure all the work I'm currently doing is open source so that people can look at their code and see what I'm up to. For my most recent completed open source game, look at IrrlichtTetris (its old I know, but I've been making all my games for my work not myself).

As for the keys-- you dont want to limit a generalized Avatar class directly to keys because:
1) you want the programmer to be able to switch which keys connect to which actions
2) you want AI systems to be able to send commands as well

Its simply a matter of sending the appropriate commands to the avatar from your event handling function: some sample code is certain to be available with the Avatar class when it is written.

One thing I do need to ask of those who've already got animation stuff going on in their projects: do you support blended animations at all? Should I worry about multiple FSMs inside of an Avatar? (ie: head/upper torso/legs) such that you could be attacking while legs are still or walking?
a screen cap is worth 0x100000 DWORDS
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

keless:
can not wait to see this class,it seems that will be great system for
controling model animation.

wish you good luck , and i am ready for any help.
Post Reply