Two characters takedown animation question

What is the best way for executing a takedown animation when the player and a NPC character interact?

I have made the takedown animation in my 3D program in the same scene with the two rigs. I import both of them in Unity, but I am struggling to make it work.

I call animator.play for exact timming but I am struggling with position and rotation of the characters.

Thanks in advance

Research Target Matching and Inverse Kinematics.

Already have, both of them, but it seems that these are not made for what I have in mind.

I have been trying this for over a year, with no luck.

It’s hard to me to explain my problem too. I have and idle animation with the root position XZ in the center of mass and the root height Y in the player’s feet. But I have another animation when I need to bake all the settings at the start position, I need to do this because, in the 3D program is use the 0,0,0 position as a reference point (I created the takedown scene and both of the player work great).

With this settings in both the player and the enemy, if I set the same root position and start the corresponding animation in each one, the result are awesome.

BUT, when I transition from the idle state in each character to the takedown state the characters jump (I take some frames to match the root positions) and then, when the animation is finishing and they are transitioning to the idle state again you see the same jump and the two characters sharing the same position (as expected when I set them equal to each other)

This aproach will be useful to me for a lot of other movements and interactions in my game, because I can use it to correctly position a player on a ledge or activating some lever or any other character to character interaction.

I really really apreciate you help.

I share the link of my channel: https://www.youtube.com/channel/UCBHr7sadp8RnyPIuM2PHL-A

Thanks in advance

This is something you should set up in your original animation. Let’s refer to the thrower as uke and the person being thrown as tori.

Let’s say tori is at (0,0,0).

Uke should start the throw slightly in front – for example, (0,0,1). Since different tori may be different sizes, the easiest way to do this is to add an empty child GameObject to tori that specifies where uke should start the throw animation – for example, at local position (0,0,1) relative to tori’s position.

The animations should be designed so that uke’s throw animation at (0,0,1) syncs with tori’s being-thrown animation at (0,0,0). Then just make sure you get uke to (0,0,1) before starting the animations.

You may also want to add more empty child GameObjects to tori to specify where uke’s hands should be during the throw. Use IK (Animator.SetIKPosition) to put the hands there. This will allow you to adjust the appearance of the animation for different size characters.

1 Like

That is a very good aproach but I doesn’t work for me, what I need is a very robust system that let me transition smoothly from idle animation to the takedown animation (synced between the characters, this is easy: animator.Crossfadeinfixedtime at the same time) and back to the idle state.

The problem is that I need to interrupt the takedown at any moment and again, it should be effective.

Also, the takedowns are very complex, because there are, one on one takedowns, counters between one, two, or three enemies at the same time, therefore the calculation with IK will be complex and unpredictible.

I have made a system that records the hip position on the player when not in transition, when certain transition is triggered, the delta position and rotation recordered are used to move the character while the transition is being played and displace the root position meanwhile. With this tecnique, once the special transition is finished, I can easely lerp the root to the desired position.

In the system I also made a future transition fixer, in order to transition from a fixed movement (such as in takedown) to an idle state.

I was also trying to get the original root position when “Root transform Position XZ” is set to center of mass and “Root transform position Y” is set to feet position, but apparently it cannot be done (at least not by me, it seem to requiere some advanced core scripting of Unity). The inverse process is possible, you can get the center of mass and pivot position with functions on animator. It will be great if you can get where would the original (0,0,0) position and rotation of the animation are when you use center of mass and feet.

I was also researching about using a helper bone placed in the (0,0,0) of the original clip so I can use it as a reference to know where the root position and rotation would be, but I am not a 3D animator and I cannot get it to work, I know that the game Tron uses this method, in fact the character has two helper bones in the hierarchy used i.e. when the character jump to a specified position and rotation to the lightbikes

I really need this system to work in order to always have the root transform in the center of mass and in the feet, so I can transition smoothly to every animation I need without hiccups

Once again, you have no idea how sorry I am for asking for help, I always research in google until I get the answer even if it take several days but this problem was beyond my knowledge and it seems nobody has the same issue, almost a year searching solutions with no luck.

I will try to make a small project to simplify this problem, because I struggled with problem so long, that I can barely understand it

Thanks in advance!

1 Like

Are you attempting to use humanoid rig in mecanim - or generic?

This seems like a complex problem. I don’t think this system can work with humanoid. With generic however, I can see it working.
Essentially - (I think) you would want to still follow your instincts and @TonyLi suggestion, but with a slightly different set up in mecanim (using generic rig and no root motion).
Also - although I’m a artist/animator who nearly always defaults to use root motion because I like to contain the locomotion within the animation - if possible, but for this problem I would elect NOT to use root motion, and instead drive the locomotion/location of the character programmatically. :hushed:

The rig would be set up kinda like this
1 master root at the most important location you need it to be [either at feet or at hips (com)].
2 positional nodes - each parented to the master root.
Positional node 1. Located wherever you want, probably the other position at feet or com - wherever the master root is not located. Controls the animations for the lower body. The legs would need a custom IK solution found on the asset store or roll your own.
Positional node 2. Probably located at com - waste/pelvis. Controls the animations for the upper body. Hands like legs have custom IK solution.
The master root has the main locomotion controller - and the other controllers have the animation logic, so the animation and the locomotion are decoupled.
This would allow the movement of the character not to be interfered with - with the animations of the character.

The animation controllers would be separate from each other either completely or separated by the animation layers - not effecting each other - but the animations on the legs and hands could still be IKed and match.targetted (I think) to hit on the other players where you need them to.
Kind of thinking it is very similar to a shummp type set up where the upper body in independent from the lower body. Each are rigged and parented to a master node - but the legs do not effect the upper body and the upper body does not effect the lower body.
Of course the separate animation controllers would have to be managed/synced (what a headache) but doable.
And the interruptions could still happen - with triggers.

This is all theory - never created a complex animation controller like this before - but knowing the system, I think this is a solid direction you probably want to test out.

Thank you very much for your quick response, This issue is driving me nuts.

I am using humanoid rig, which is the best configuration for the features it provides (mirror, IK, matchtarget, etc)

I think that your system is very versatile, but also very complex because you need to calculate and programatically move not only the player but all the enemies as well. But I think the same you do, I like root motion for the simplicity and realism. But I disable it sometimes and move the player by script, depending the state.

This is my channel in youtube: https://www.youtube.com/channel/UCBHr7sadp8RnyPIuM2PHL-A

As you can see I am doing a Batman Arkham series clone, as I rip the animations from the original game I realized that the developers use the (0,0,0) position and orientation in the 3D program as a helper in order to sync several characters and player interaction with switches, levers, etc.

This is clearly a clever aproach in order to get smoothness, accuracy and syncing. Unfortunatelly Batman series was made in Unreal so I do not have time to investigate as I am only a physician who codes only in my spare time and I prefer Unity.

I belive this would be very useful tool if I can figure how to get the root original position. If I dig depper into this issue I only need to know the offset between the hip transform, and the original 0,0,0 position at the current time in the original animation (just guessing: I need to take a desired frame of the animation and calculate how rotated and moved is the hip relative to 0,0,0. But as I previouly said: It’s beyond my knowledge)

Just look at the first half of the next video and you can see the player jumping over a fence. Look that the 0,0,0 position is in the bottom of the fence. The developers use this helper point to make several animations for jumping over, with no hands, with a foot, etc. they work all great because the core code is the same, If you want to make parameters and curves for each one you will be mad. You have to configure if the anim uses the right foot, the left hand, no limb at all, the time of match starting and ending, the orientation, etc.

Don’t look at the second half, it’s not what I want, my mistake.

I am currently trying to add, in the character’s rigs in my 3D program, a bone, parented with the hip bone, and fixed all the time in the 0,0,0 position and always facing forward. I think that I can expose this bone transform in the characters avatar and get its information for my purposes, but I tryed several configurations and none of them work, maybe because I don’t know how to work with bones, keyframes and other 3D artists stuff. No doubt you do.

Thanks again for your time and specially, your patience.

Consider just a couple tests with generic. From your explaination I dont think this is doable using the humanoid system. Its too contankerous in my humble opinion for the type of complex system you are attempting.

Id put money on the table to wager if a game like batman or assasians creed was created in Unity, the developers would choose generic over humanoid and provide custom solutions for the features built into the humanoid system, IK and mirroring.

here’s an idea (untested):

make it 2 animators (one for transitions) for each character
when the characters are close and you want to do the transition

//set to first frame
animator2.Play(“takedownanim”, 0, (1/total_frames)*frame_number);

//get bone transforms
hiptransform = animator.GetBoneTransform(HumanBodyBones.Hips);
hiptransform2 = animator2.GetBoneTransform(HumanBodyBones.Hips);
etc.

//lerp transforms (or matchtarget)
if (lerpValue < 1){
    lerpValue += Time.deltaTime / 10;
    hiptransform.position = Vector3.Lerp(hiptransform.position, hiptransform2.position, lerpValue);
}

//start animation
animator.Play("takedownanim");
1 Like

I think and believe that there is some way to achieve this. But I cannot figured it out.

I really don’t want to set the avatar to generic, I will have to write all the code again and I’ll lose all the benefits of humanoid in mecanim.

Still trying to use the 3D program in order to add a helper bone parented with the hip. Have you tryied? I literally suck at 3D animation creation. I don’t know how to make the bone strecht or be fixed in certain position and rotation.

Thank you again for your quick reply, meanwhile, I will investigate a little more

Nice aproach, you need two animators, but each one with a different animation setting, the main Center of mass and feet, the auxiliary baked all at start, then you only need to lerp the main hip position to the helper one.

I will try to go arround this. however you need to animators if there are two characters, if you have 4 character interaction things will get hard.

And I need to use Animator.Crossfade for a smooth transition, otherwise the character in a crouch position i.e., will instantly get up and start the takedown.

Thank you very much for your contribution. I will research all the methods to achieve perfection on this.

Greetings!!!