- Home /
How to have an object mimic another's animation
Hey everyone,
So I have two objects, right now I'm just using the default construction worker in the Character Controller asset package, and I want them to behave in the exact some way at all times. What I mean by this is one of the characters will be controlled by the player and will behave normally. The second one should simply copy the position, rotation, and animations of the first character.
I am currently able to update the position and rotation in real time accurately simply by doing
obj2.transform.position = obj1.transform.position;
obj2.transform.rotation = obj1.transform.rotation;
but I cannot do that with the animation component. All I've been able to do is stick the ThirdPersonController onto both objects which is not something I really want to do.
So is there a way that I can update an object to mimic the animations of another in real-time, assuming all the possible animations are known ahead of time?
You shoudn't do position syncing, but animation syncing... don't set all positions and rotations to the same, ins$$anonymous$$d set all the animations to the same, it's easier and faster.
Ok, but I'm not sure how to sync the animations hence the question. Do you know how to sync these animations or any resources that will help me figure it out?
I can't right now, but reading the documentation might be a good idea, figuring out how animations work: http://docs.unity3d.com/Documentation/ScriptReference/Animation.html
I have looked through the documentation. Perhaps I'm just dense but I didn't see an easy or straightforward way to do it. The only thing I could think of is to save any function calls to the obj1's animation component and make the same calls to obj2's animation component which with my current setup would be awkward. Also I'm not sure if that would save me any time since I'm already doing this in a roundabout way by having a ThirdPersonController on both objects.
Also, as far as I know an animation doesn't actually move the players position so how will the second object mimic the movement/displacement of the first object if I only sync the animation?
You probably didn't understand it proerly, but you can loop through all animation states (as seen in the docs). You should be able to loop through one, and set it to the other :)