Updating Hurtbox Entity to Match character animation.

Hello,

I am currently developing a hitbox/hurtbox system. The first thing I need to get right is having entity with physic bodies matching the character’s animation.

Now, animation doesn’t have a DOTS equivalent just yet, so I am currently using a hybrid system. GameObject handles the animation, the rest is handled by ECS.

Here is a challenge, because I need to use LateUpdate to get the position of the Character Bones (like the Head or the arms), write that on a component, and then have a system use the data of the component to move the colliders around.

There is an issue - the ECS transform system runs before LateUpdate. So whatever I do, it has to be after the TransformSystem.

I tried updating LocalTransform, but it updates one frame later.
I tried updating TransformAspect, but the same thing happens (LocalPosition and WorldPosition both update one frame late)
I then went with something that usually works, which is just creating a new LocalToWorld and replacing that. Then the movement matches the position perfectly.

However, the colliders are not uniform in scale. So when I create a new LocalToWorld, the position and rotation update, but the collider is wrong scale (1,1,1). I tried many different ways to keep the scale or reset it, but it doesn’t work.

My question is two fold:

  1. What is the correct way to go about this? Remember that I must get the info in LateUpdate, as I’m following the animations.

  2. If I do have to create a new LocalToWorld, then how do I keep the scale? How do I create a float4x4 with rotation, position, and scale?

Thanks for the help! Looking forward to the answer, as this is a very common situation in any action game, and the reply may benefit future people working on the same thing.

Cheers.

edit: I have found a partial solution, but the problem is still there - I still haven’t found a way to correctly update instantly the position of an entity, to follow the bones of an animation of a gameobject. I still need insight to solve this. Details in the latest post.

It sounds like you are not using 1.0.0-pre.65. The transform system changed in 1.0.0-pre.65. Try updating to that first.

I have updated to version 1.0.0 pre65.

  1. I have noticed that while updating LocalToWorld directly makes the render mesh follow the movement without lag, I think the physics are tied to LocalTransform. Because I’m not modifying it, the collider isn’t moving, although the entity is being rendered at the right location.

  2. If I update LocalTransform, then the Collider moves correctly, but the movement follows with 1 frame of lag (so it looks delayed).

So how should one go about having an entity follow both in renderer and collider the animations of a gameobject? The first solution doesn’t update LocalTransform, so the collider stays stuck. The second solution has a frame of delay.

I have read the documentation and looked for answers, but so far I haven’t found anything explaining how to solve this particular situation (which I think is fairly common in an action game).

If someone that has managed to solve this, or someone from unity could share an insight, that would be amazing, because atm I’m stuck.

Modify the localtransform for any rigidbodies.

Hello,

Thanks for the help. But as I’ve stated before, updating LocalTransform has a frame of delay. When you move the character, it looks as if the collider is following him like a trail instead of being stuck to it. So this is not an option.

This is because I am updating the Entity transform AFTER the TransformSystemGroup - meaning LocalTransform has already been processed. So the TransformSystemGroup runs the frame after, and then it updates the position - but the animation will change on LateUpdate, so it looks a frame behind.

There is this whole paragraph on ECS documentation talking about entity transforms, and how sometimes you need to use “ComputeWorldTransformMatrix” method to get an instant result. I checked the documentation page to see how to use it, and while it does a great job talking about the method itself, I still have no idea how to use it on a SystemBase, or ISystem.

I imagine that the context of needing an Entity with a Physics Collider keep up with the Bone after an Animation is a pretty standard use case in fighting games or action games. But it has been such a cryptic transition from 0.5 to 1.0 - How in the hell do you move an object after TransformSystemsGroup reliably in the same frame? Both render and collider.

LocalToWorld updates only the mesh, not the collider (I guess collider is based on LocalTransform - since I’m not touching LocalTransform, the collider thinks it’s sitting at the same place)

LocalTransform updates both mesh and collider, but with a delay (We can’t have delays on fighting games - we need top notch up to date information) (this happens because TransformSystemGroup happens, LocalTransform is processed - LateUpdate happens, animations changes, I update entity transform to match animation position. LocalTransform is now out of date with positions, and will update next frame to match new animation positions. but then animation happens again on LateUpdate(), and so on…)

Thank you to the devs, the users, and anyone that came across this problem and successfully solved it. Your help means the difference between me working on my game this week, or being stuck on this. :hushed:

Don’t you also have to account for Physics copying the colliders and transforms into its BVH structure? I think for that reason your best option will be to make SimulationSystemGroup update after animations using the PlayerLoop API.

Otherwise, you’ll either have to deal with some sort of frame delay or switch to a pure ECS animation solution. Personally I went with the latter, because I wanted a tight level of control between animation and other gameplay mechanics like collisions.

If there was a way to switch to ECS animation, I’d do it. Is there any guide or video or anything that teaches this? I had no idea it was possible, so I was limited to the animator. If you can share sources or anything I’d be happy to learn.

There’s nothing official, but there’s a few third-party solutions. I made one of them. Best resource to explore is here:

Ok, so I took a look and learning a pure ECS approach seems to be an important decision and investment of time.

I think it will pay off in the long run, due to increased performance - however, it does seem like it’s going to take a few days/weeks to learn.

  1. I will try the system you’ve created. Will using your framework solve the issue I have of synching the collider with the entity bone after the animation?

  2. I would still appreciate someone from Unity team sharing with us how they would go about something this. Like I said, this seems to me like a very common situation. Is it really impossible to synch entity collider with bone animation on hybrid approach?

Perhaps they would reply to this over the discord? I really would like to hear an official stance on how to go about this.

Thanks for the help.

It is in a little bit of a rough state right now, as it got hit pretty hard by a couple of Unity regressions. I’ve since been pushing it in a direction to help mitigate these sorts of issues in the future, but I’m still debugging the new implementation. Hopefully I will have something official again in a month. With all that said, it gives you complete control over when and how the animation gets played, so you can easily tie it to whatever gameplay mechanics you want.

Definitely worth checking. They’ll probably point you to the Character Controller NetCode FPS sample project. I have no idea if it works the way you want it to though.

set Animator’s UpdateMode to Animate Physics instead of Normal, then animation will update in Physics phase.
then Bone transform is fresh for Update and SimulationGroup.

ref: Unity - Manual: Order of execution for event functions