Sat, Jun 27 2009 9:30 PM
Spartan MVI
Avatars - Introduction
It's been a while since I wrote here, however below is the first in a
series of articles I will be writing on the use of avatars with XNA.
With the addition of Avatars to Xbox 360 last year in November, it was
only a matter of time until games started supporting them. With the
recent development of XNA 3.1, support has now been added to include
avatars in your own games.
The Dos and Do Nots
Avatars form part of the Xbox experience, and as such there are
limitations on what you can do with them. Because they represent a link
to Microsoft and Xbox, it could be perceived as damaging to their
reputation to allow you to go round making "murder simulators" or
recreating "hot coffee" and releasing it. Indeed, as avatars are
officially supported by Microsoft it could be interpreted as Microsoft
supporting murder games. But that's just getting into the grounds of
downright silly.
To help you with creating games which don't go against the rules, an article
has been provided on the Creators Club website detailing what can't be
done. To briefly summarise, it states that the player's avatar cannot
have a mind of its own, excessive violence is not allowed, anti social
behaviour is also a no-no along with replacing/obscuring avatar
features and modifying avatar proportions beyond a uniform scalar. I've
heard several people misinterpret the list however, believing that you
can only use avatars which belong to the player. The list however
states that only player characters are not allowed to be autonomous and
only player avatars are not allowed to talk. Presumably it's fine to
build games with many avatar NPCs, as long as the player's avatar isn't
one of them. (I guess that the chance of a randomised NPC avatar being
the same as the players custom one is just grey enough to be
allowable.) I would also assume its fine to have non-player avatars as
key characters in specific roles and cutscenes. It's just the player's
avatar which will not be allowed to talk or interact in cutscenes
(remind you of GTA III?)
As a guideline, Microsoft have stated that only games which
are suitable for age 10+ and age ratings below may feature avatars.
Meaning any game which would require a rating higher than 10 years of
age is not suitable for inclusion of avatars. It might be an idea to
have a look at games in the E10+ category, though its quite limited
theres still a lot of room, and if you tone down some of the elements
of a game which might not be suitable, I'm sure you could get it
working.
Creators Club Samples
Three samples have been provided, I suggest if you haven't
checked them out already that you download them and take a look at the
way they work.
Avatar Animation Blending Sample - shows how to blend one
animation into the next, tweening and morphing bones so that you don't
get judders and obvious bone repositions when the animation switches.
Avatar Multiple Animations Sample - shows how to combine several
animations at the same time on different parts of the body, this sample
for example has the body using the celebrate animation while one of the
hands is carrying out the wave animation.
Object Placement On Avatar Sample - shows how to calculate the position
of particular bones, and then have a mesh "stuck" to that part of the
body. The sample has the avatar with a baseball bat stuck on their
hand. Anyone fancy making a baseball game?
How do avatars work?
Avatars are based on skeletal animation for the movement of the
body, and rely on changing textures for the facial animations. Each
avatar contains all the data relating to its unique state, such as the
skin colour, clothes, facial features and other details. It is worth noting that you can only use avatars on Xbox 360 builds, they will not work on PC or Zune, meaning that you need to use XNA Game Studio Connect on the 360 to use them.
XNA has added a number of classes for animation support, as listed below (class descriptions stolen from creators site):
AvatarAnimation - Provides methods and properties for animating an avatar using standard animations (for example, celebrate).
AvatarDescription - Provides access to the methods and properties of the description data for an avatar.
AvatarExpression - Contains the various components of the avatar's face, such as the left and right eyebrows.
AvatarRenderer - Provides properties and methods for rendering a standard avatar.
AvatarAnimationPreset - Defines standard animations for avatars.
AvatarBone - Defines a list of the useful bones of the avatar model.
AvatarEyebrow - Defines the standard animation textures for an avatar's eyebrows.
AvatarEye - Defines the standard animation textures for an avatar's eyes.
AvatarMouth - Defines the standard animation textures for an avatar's mouth.
There have have also been two additions to the SignedInGamer
class allowing you to use the signed in players' avatars and to detect
whether they have been changed.
SignedInGamer.AvatarChanged - Occurs when a gamer's avatar changes.
SignedInGamer.Avatar - Description data for the avatar that represents the gamer.
Custom Animations
While I haven't found any mention about if custom animations
are allowed in XNA (please let me know if you find any material saying
it is), it would be logical to assume that it's allowed, especially
based on the structure of the avatar support in XNA 3.1. Since the
animations that come supported are very limited, it would be very good
to add some more, running/walking/jumping/driving etc. The guys at CoderNet.es
have made some excellent work on this front, creating custom animations
in 3ds max, then getting these animations working in XNA. You can check
out a video tutorial which also demonstrates the finished in game
animation at Youtube.
You can also download the source code, along with two Max files. One
containing the base biped (unanimated and in a classic T), the other
contains the animation he creates in that video (arms spread like
wings, going from side to side.) Using this, you should be able to
create your own animations, and get them working!
Useful snippet
Finally, although this is just the introduction article to the
series there's still a snippet of code which you may be interested in
if you don't know about it.
The samples currently just generate random avatars and draw them, while
this is a nice feature it comes second to being able to use your own
avatars. To set the avatar description to an actual player's avatar use
"avatarDescription = Gamer.SignedInGamers[PlayerIndex.One].Avatar;"
Filed under: MVi, XNA, Avatars, XNA 3.1, Animation