I have the following setup:
- a kinematic rigidbody (which btw, doesn’t have a collider nor mesh – I’m only using it to establish a joint between it and a child rigid body / collider / mesh representing the visible game object in my scene).
- An animator component attached to this rigid body. The animator controller has a single default state, with an animation clip recorded via the animation window; it’s a bobbing / sinusoidal motion along the Y axis.
- A “player input” script which, on
FixedUpdate
basically gets the vertical axis and does something along the lines of:transform.position = transform.forward * 5f * verticalAxisValue
So the idea is:
- The rigidbody is kinematic, so I can translate it via its transform.
- Again, the rigidbody is kinematic, so it should also be ok to animate it via curves.
But the problem is that, the minute I enable that animator, the bobbing animation plays and it seems to completely override my attempt at manually setting the transform via code (step 3 above). That is, if the animator is playing, any attempts to additionally further modify the transform in code are ignored, regardless of the animator’s update mode or root motion option.
The one workaround I found so far is to enclose the above setup in an empty parent, and instead apply the programatic transform changes (step 3) to the empty, so that I translate that transform, while the rigid body animates according to the animator state within its local space. But I’m wondering if there is a way to do this without the extra empty?
I also tried creating 2 animator layers, leaving the base one with no states, while putting the bobbing state in the second one and giving it a weight of .5 and blend mode of additive. I was hopping this would “add” the animation to any programatic transform changes, but it didn’t work.
Also, kind of related, I’d assume the animator clip is modifying the transform / rigid body in local space, relative to the empty parent, but if I rotate the parent, the animation seems to still apply to global Y, regardless of the rigid body having globally rotated as a consequence of it being dependent on its parent’s coordinate space.