- Home /
Can't get my Unity 2D animation to play properly
I created animations from within Unity using a multiple sprite sheet where all the body parts were separate and assembled into the scene. I have a Player object with a child for each object for the player facing up, down, left, and right, with children for each object for their body parts facing those directions. The objects for each instance of the character are stacked on top of each other in the scene.
Using blend trees for idle and walk animations, I was hoping to smoothly transition between animations. Perhaps since each directional character exists in the scene under one parent, I can't seem to deactivate individual objects of a directional character on starting the game. Using animation to deactivate the other objects for when the current character is animating produces this funky result:
The overlapping doesn't occur if I set transition time to 0, but it's not the effect I'm aiming for. How can I get this to work, or how can I build my animations to prevent this from happening in the future?
Answer by Dibbie · Jun 14, 2016 at 08:30 AM
It may be easier to have your animations on one sprite and create "frames" instead of animating different sprites.
Though with your issue here, since you are trying to hide objects when your character stops, sub-child them in your parent instead. So you you may have a higherarchy that would essentially look something like: Character UP_CharacterHead UP_CharacterNeck UP_CharacterTorso ... LEFT_CharacterHead LEFT_CharacterNeck LEFT_CharacterTorso ...
And so on...
Then you can just "hide" for example, "LEFT_CharacterHead", which would also hide all the children to that - but that all exists under your generic "Character" sprite, which your body parts are built up of.
With this particular case, do you mean something along the lines of having each individual body part for each direction inside one single parent object?
Could you also describe more about the "frame" creating idea? I am very willing to try other methods to solve this. Anything along the lines of having one player character that can be animated in four different directions using individual pieces.
Thanks for the input!
Yes, thats exactly what I mean - youd have 4 parent objects inside one master parent object in a way.
The more common alternative, is putting your sprites in one image. So you would create a PNG image of your character "constructed" ins$$anonymous$$d of doing it in Unity, youd do it in something like Photoshop or an image editor. Youd create the facing directions there, so when you save it, ins$$anonymous$$d of saving "Character_LeftArm", and so on, its all in one image, youd save it as "Character_LookingLeft" etc...
Back in Unity, you can then take that image to represent your player, and when moving left or right, you could either "flip" the image with Unity's built-in method for that on Sprites, or hide Character_LookingLeft, and show Character_LookingRight, for up and down same kind of idea.