- Home /
Sync animation between multiple gameobjects on trigger
Hello all, ive been trying to find a solution or perhaps phrase what im looking for better. I have three game objects. when an event triggers I simply want to remove control from all players and carry out a series of movements/animations. For example a scripted combo where Player1 walks to Enemy(regardless of where they were when event triggered), punch enemy, the enemy now plays an animation/movement to the punch and is sent towards Player2, whom then plays another attack animation of some sort.
I can't seem to wrap my head around how to get the characters in place or how to play these individual animations and ensure they play out in sync with one another. Could someone at least help me to define a definition of what it is im trying to accomplish, perhaps I could research this better if I knew exactly what this was called.
Answer by smileteam · Oct 21, 2016 at 11:41 PM
Well, this kind of thing is very simple once you break it down into pieces. I'm not entirely sure what this is for, whether it's third person, first person, topdown, etc. so I'll try to give the best answer I can with little information.
So let's try and break it down anyway :
You have three characters. Each of them has a control script, whether that's player controlled or AI controlled.
They'll have an animation/animator component, something that contains the animations you want each of them to play.
You have "Points", yes? Where the characters will start and/or move towards.
Once you know what you have and what you need, we can start doing things.
You'll have to create an animation manager of some kind, it will have references (variables) to everything involved in the animation, that would be your characters, and movement points.
You should also create an Empty Gameobject root at the position where you want Player1 to be when it's "punching" Enemy, parented to Enemy.
Once the event is triggered the manager will disable the control scripts for the characters. Using this.
All characters should now be completely still and not move.
The next step is to move Player1 towards the previously created empty gameobject which should be parented to Enemy.
Whatever movement script you are using, you can use their movement function, or if you want something even better, create a Navmesh and Navmesh Agent for the player, so when you disable the control script, Player1 can move towards Enemy using the best path possible. While they're moving, just play the run/walk animation that you normally would play, or a leap, jump, or what have you.
Repeat for Player2 of course.
When the Characters get into position, just play the animations in turn (I don't know if you're using mecanim or the old animation system, but you should just be able to "waitforseconds" and trigger the next animation if you're looking for a quick and dirty method), and it should work out fine. Of course using the manager, re-enable all the control scripts so they can all move again.
Your answer
![](https://koobas.hobune.stream/wayback/20220612095136im_/https://answers.unity.com/themes/thub/images/avi.jpg)