I bought an asset the other day containing an Atlas of character parts (head, hairs, clothes, body-parts). It's great and allows me to tint each piece any color I want. However, The artist decided to devide up the character like this:
Each child is a fully setup character, facing a certain direction, with an Animator
attached to it, inside each Animator Controller you find this:
Some sample animations, pretty self-explanatory.
However, I have never worked with sprites like this where its several parts, the entire character is maybe 30-40 parts (allowing for some fun animations).
I'm used to making Blend Trees
(on a single GameObject
) and have one animation for each direction.
The best solution for controlling these animations I could think of was something like this:
private void AnimControl() //call in update
{
if(direction != directionLastFrame) //do not run method if we are moving same direction
{
//standing still
if (direction.x == 0 && direction.y == 0)
{
directionLastFrame = direction;
}
////left
else if (direction.x < 0.5f && direction.y == 0)
{
currentCharacterDirection.SetActive(false); //set current gameObject (which is a character facing a certain direction) inactive
currentCharacterDirection = character.leftDirection; //change to correct direction
currentCharacterDirection.SetActive(true); //set gameobject active again
anim = currentCharacterDirection.GetComponent<Animator>(); //set the animation controller to the new gameObject
directionLastFrame = direction; //set the new direction to check for
}
////right
else if (direction.x >= 0.5f && direction.y == 0)
{
currentCharacterDirection.SetActive(false);
currentCharacterDirection = character.rightDirection;
currentCharacterDirection.SetActive(true);
anim = currentCharacterDirection.GetComponent<Animator>();
directionLastFrame = direction;
}
////down
else if (direction.y < 0.5f && direction.x == 0)
{
currentCharacterDirection.SetActive(false);
currentCharacterDirection = character.downDirection;
currentCharacterDirection.SetActive(true);
anim = currentCharacterDirection.GetComponent<Animator>();
directionLastFrame = direction;
}
////up
else if (direction.y >= 0.5f && direction.x == 0)
{
currentCharacterDirection.SetActive(false);
currentCharacterDirection = character.upDirection;
currentCharacterDirection.SetActive(true);
anim = currentCharacterDirection.GetComponent<Animator>();
directionLastFrame = direction;
}
}
anim.SetBool("Moving", playerMoving);
}
I mean it works, but feels wrong? Anyone that can think of a better Idea here, worried this might be too slow. setting an object to active/inactive too often.