So I’m new to unity, and have been learning how to make games with unity the last several months, and I’m stuck on how I would go about animating facial expression on a 2D character. I know how to use the sprite animator inside of Unity through transformations, but I don’t know if facial expressions can be done the same way. I’m thinking the frames need to be saved out ahead of time and then loaded into unity as an animation. The expressions I want to achieve are a bit dramatic and animated, so distortion alone wouldn’t cut it.
Can anybody body give me some tips on how to go about doing this?
I’d probably go for separating the eyes and mouth from the faces and keep them as separate assets. You could assemble them in the game, and animate them all independently (eyes and mouth shapes and head movement). This should cut down on the number of sprites you need.
Can you elaborate on what kind of facial animation you’re doing that prevents you from just having different sprites for each expression? Maybe I’m way off on my assumption of what you’re trying to do.
Yeah the problem is that I’ve found when trying to animate 2D facial expressions is that I – AND SEVERAL other devs I’ve spoken with – an’t set a specific start time, even with the cycle offset button. So do what Hyblademin said; if nothing else, pop into an editor that can handle .png’s and just resave that first frame 10, 20 times to get the right frame set. Good luck!
[QUOTE="Can you elaborate on what kind of facial animation you’re doing that prevents you from just having different sprites for each expression? Maybe I’m way off on my assumption of what you’re trying to do.[/QUOTE]
I think I can have separate sprites, I just don’t think I could deform the sprites to pull off the animation I want, other than maybe the eyes. But the game is stylized like a cartoon - like a flash game. My character as a small line for a mouth, and when he eats something, his mouth get’s huge, shows a tongue and his teeth. He also has a shocked expression and a cringe expression.
I guess the part I’m confused about is do I need to have the elements of all those facial animations imported with the rest of the character and set up in the atlas in unity? And if so how do I use them since they’re not constantly visible? Would you just control them with the state machine and some code? I’m thinking about animating inside unity with the parts of the character through keyframes, which is what I believe you were suggesting anyways.
Essentially, my suggestion is to build the face out of several game objects, each with their own sprite-- eye, mouth, so on, with all sharing a parent object. Then you can animate them all simultaneously and independently.
Use Mecanim (the Animator component) to set up the different animations. If you want to be able to mix animations between, say, eyes and mouth, use different Animator layers or just give each section its own Animator (performance implications of this are unclear, but I haven’t had any problems).
You can use the Animation view (not to be confused with the legacy Animation component) to animate any property found on a component in the object-- this includes localPosition and localScale, as well as the sprite used on the Sprite Renderer. I imagine that animating these three properties will allow you to achieve close to the style you’re looking for.
Deformation will be harder. I suppose you can use an animated quad, or possibly find a special shader to use.