Hitbox collider offset problem in imported root motion animation

I have a bit of an issue trying to get a hitbox to work with my animation.

Here’s my setup:

  • I have an imported root motion animation
  • I duplicated the animation so that I could edit it in the animation tool in unity
  • I added a child game object to the character with a 2d collider on it (this is my hitbox)
  • I animated the collider to coincide with the punch animation
  • Because the animation for the collider is in the same clip as the mesh animation, it’s on the same animation controller (in case that’s not obvious).

This looks fine in the preview when I scrub the animation or play it in the animation window, but there’s an offset when I test in playmode.
This is the animation when I set it up in the animation window. Looks fine.
3162668--240667--example1.PNG

Same animation when I test it in play mode:
3162668--240668--example2.PNG
I chose this workflow because it allows the designer to easily tweak hit frames, etc, and you can preview it easily. Having to animate the hitbox on a separate clip/controller would be a nightmare to line up.

So, is there a way to fix this, and/or a better workflow to animate the collider?

EDIT: This behaviour was observed in 5.6.0, 5.6.1 and 2017.1

Thanks!

Humanoid or Generic rig?

It’s a humanoid rig.

I should also add, in case it’s not clear from the post, that the character itself animates wonderfully with root motion.

I’m not sure why it’s happening, but what about making the collider object part of the character asset itself, eg. 2d plane standins for the hitboxes? Then you could animate the hitboxes along with the rest of the animation. In Unity you’d hide the plane’s renderer and add a matching collider. This could also make later changes easier, since you wouldn’t be duping the imported animation.

We’ve definitely considered this option–that said, I’d much prefer if the designer had the ability to do the tweaks in Unity rather than having to do them in Maya/Max. I’m thinking it’s a good fallback to an in-editor workflow, but I’m hoping there’s a simple fix to my current issue.

Either way, thanks for the feedback!

What happens on the next animation cycle? Does the hit box move as desired but delayed?
A video or gif of both preview and in play mode would be helpful - showing more than one animation playing sequentially with the results of the hit boxes showing.

I’ll do a gif later tonight and post. That’s a great idea.

The offset is always the same. I can trigger the punch animation from any location, move the character, do it again, and the offset is still wrong (but the same relative distance).

@theANMATOR2b
Here is the preview in the animator: Imgur: The magic of the Internet

Here is the behavior in play mode: Imgur: The magic of the Internet

That looks like a double transform. I don’t know if that happens in Unity, but it’s common in other systems. The collider shares the animation clip and animation controller, but is it a separate asset with its own Animator? It could be getting moved by the motion of the character you parented it inside, then moved again by the hitbox animation. If so, you might try making the GameObject the collider lives in exist in the character asset, iand adding the collider to that (so there’s only one Animator), instead of parenting a new object inside the character.

It actually is on one animator. The character animation also drives the collider animation.

Can you do a simple test - parent a non-animated hit box just like you did with the existing hit box and see what the results are?
I agree with @NoiseFloorDev - this does look like a double transformation.

Are you using root motion (I don’t know if this matters)?
If so - by turning off root motion in the inspector - does the hitbox still offset incorrectly?

Edit: Where is the hit box parented in the character hierarchy? Can you show your character hierarchy?

Also might consider looking into some of the asset packs on the store that are related (hitbox). I bet you might be able to solve based on referencing those - and possibly the supporting forum threads.

@theANMATOR2b
I tried a second hitbox with no animation, and its offset is correct.
I am using root motion animation.
Here is a screenshot of my hierarchy:
3169909--241434--EXAMPLE3.PNG
Colliders contains the hitbox (the copy is the one I was testing with per your question)

We are eliminating things. :wink:

Are you familiar with animation layer masking? IDK if this is a solution but thought I’d mention in case you are not familiar.

The hit box is inheriting the root motion translation - based on the the test you performed.
So - you are going to have to research parenting an animated object to a root motion controlled character - without inheriting the root motion transform.
Does changing the animation set up root motion options in the inspector for the hit box solve?

Root Transform Positoin (Y), (XZ)

Alternative (probably not optimal) syncing a separate animation controller for the hit boxes with the existing character animation controller.

Found something that might help - kinda related but in reverse.

@theANMATOR2b this looks promising! I’m going to give it a shot and report my findings. Thanks for the help so far!

@theANMATOR2b
Unfortunately, this approach did not work–it overrides the default root motion behavior on the biped with the animator, but doesn’t do anything for the collider.
The result is the character loses root motion, and the child collider is still offset.
Back to square one.

1 Like

Wish it was as simple as it is in 3D - uncheck do not inherit from parent - rotation,translation,scale, x,y,z.
That would just be too easy! :frowning:

From google - it seems maybe the ‘workable’ solution is to move the hitbox via code - but I refuse to believe that is the ONLY solution for this. There should be a simple animation solution.

Summoning @Mecanim-Dev

Right??? It just seems odd that there isn’t a simpler what to solve it.
I’m doing some timeline research right now to see how that interacts with Mecanim. Animating the collider in timeline works fine, but then I have some animations in mecanim and some driven via code + timeline/playables

Their is of course other solutions.

  1. Create the hit box in 3D and animate it as normal in 3D. In Unity use avatar mask to allow for humanoid retargeting.
  2. Create the hit box to be the size of the fist, parented to the hand (not animated) so when the hand shoots forward the hit box ‘hits’ with the fist instead of having the hit box be the size of the arm.
  3. Have the hit box positioned where the punch will occur and turn it on/off when needed. (not the best option)

Of the 3 solutions that will solve the problem, I prefer #1, but would still like a solution that allows for the hit box to be animated without multiplying the root motion translation.