Can I Animating a pair (or more) of Characters with one animation controller?
Okay, as part of my Game story, I want the player to attend a Royal Ball at the palace and to fit in he will need to choose a dance partner and try to fit in under cover.
What I would like is to create two clips. One of the player leading, and one with his dance partner being led as they dance.
Ideally, I would like the player and his dance partner be handled by one controller where the Player is the primary and the partner being linked into it and made to follow his lead all with one Animation controller.
But for the life of me I can not figure how how I would go about that and keep both animations in perfect sync so that at times, I can throw a QuickTime even and if they botch the QTE then they flub that part of the dace but pick up soon after and have another twirl on the floor.
If not from a single Animation controller how would I go about getting two or more characters to be animated with different clip that are all designed to work together frame for frame to make a complete animation with several character at once interacting with each other?
Thanks in advance for any advice or help in this...
Answer by Pinkuboxu · Oct 27, 2019 at 04:43 PM
Are you making a Pirate's! type game :D? Well, the Animation Controller can be the same for two characters but the Avatar may need to be different if there are different bones. Best to keep all of the bones in the skeleton universal to one Avatar, since I doubt you are going to have dancing with quadropeds, so that's probably easier. Hopefully you are familiar with the Animation Controller's state machine node editor. They used to call it Mechanim but I rarely hear that name.
Have to have two State nodes in the state machine that come off the Animators "Entry" Transition node. You'll need a parameter inside Mechanim like a bool. Maybe call it "isPartner". In a script you need to have a reference to the lead and partner character's individual Animation Controller components,
public class DanceController : MonoBehavoir
{
// you can simply drag the dancer objects onto these public variables in the script component, from the hierarchy to reference to their animators and to access the functions. If you prefer, make sure you do so with GetComponent<Animator>() in the Start() event with some other means of gaining access to components outside of this script components scope.
public animLead;
public animPartner;
void Start()
{
// reference any external components here if necessary
}
void Update()
{
// trigger all transitions here using whatever method your specific game play calls for. Remember to trigger one animation parameter per object to sync right after the other so they sync on the same frame.
}
}
so you can send a { animPartner.SetBool("isPartner", true); } command to the partner and false for the lead, IF they ever change roles. Otherwise you can just set them manually in the Animation State Machines parameter editor. You'll have to have a Transition to the Partner State node from Entry so that it understands the animation it should be using initially for the partner, and so that you can branch the separate animations from each other.
Each dance pairing needs a node. I'd put the Partner Node below the Lead node, then have the partners dance move nodes below the partner, and the lead nodes above the lead characters node. Then you link transistions from each partners nodes, giving them conditions based on Animation Parameters, and set them in your DanceController with Animator.SetBool or SetInt or whatever type of parameter you need to control the flow of the dance.
Syncing them should work fine as long as each dance move was made with the same amount of frames as the corresponding ones. Just make sure you trigger both animations, with the SetBool command in the same frame, or more easily put, one line after the other in your code with nothing in between. This ensures that each transition takes place at the same time. Don't change one transition state timing unless you also change the corresponding one to match because the State Machine handles timing for you and fiddling with the Transition speeds will make two animations that are synced in your Animation editor or 3d modeling program. Likewise the animation speed itself shouldn't be changed unless the corresponding dance animation speed is changed to match up with it.
I'm trying to also think how to do this with Layers, but layers are more for blending and syncing animations in a single character. You could technically switch from the player controller, to a set up where your dancers are one mesh using the same animation controller component. I mention that below but it doesn't really seem like a great solution, but a possibility.
That is the best I can describe the process. There is also simply combining all the animations together for both characters in one big skeleton, so that each dance is just one animation for two combined objects, but you'd need to have a means of swapping out geometry if you had multiple partners or a the main character had different meshes, like a suit or dress for the dance, and that all doesn't really leave much room for flexibility. There are also tools on the asset store that allow for real-time animation of skeleton based characters inside of Unity that would probably help a lot, but the arey not free.
Your answer
Follow this Question
Related Questions
Animation Trigger (Rpg Kit) 1 Answer
Ethan 3rd person character 1 Answer
My object spinning itself (HELP) 0 Answers
Model is distorting when animation is running 0 Answers
help to connect two objects together 0 Answers