Here’s what I could manage to do without over-engineering it. Mind you, the result might be a bit wonky since I am mostly working with Mixamo animations, maybe creating your own animations helps in achieving a better result.
Bone Attachment Approach:
It definitely works. But does it work well? NO!
At least in my case, since I have to affect 3 (or more) bones and all of them must follow on a “priority” basis, meaning that a child bone should rotate only once the parent has reached peek rotation. It also introduces a rather unexpected behaviour: modifying the bone attachment, correctly impacts the skeleton but somehow does not impact other bone attachments IF they are placed outside of the hierarchy you are using to bend the spine.
Like so, for instance.
Weird? Perhaps. I have no idea, as I am not extremely knowledgeable on how the Skeleton3D
works behind the scenes, so it might also be this is intended behaviour.
I’d give 2/10 to this solution as it is quite difficult to manage through code, there’s a big margin for error, and likelihood of spaghettifying your code is exremely high.
LookAtModifier Approach:
Definitely the most straight-forward approach. Simply add a LookAtModifier
for each bone you want to impact, set your target, constraints, and whatnot, and… done.
In my case I used a Marker3D
under the camera RayCast3D
as target (since that’s what I use to detect what the player is looking at). I applied the modifier only two 3 bones: Head, UpperChest, and Chest.
Using only these 3 bones gave me the best result for the kind of animations I am running. Applying a modifier to the Spine and Hips might result in unwanted behaviour, since in my case those bones are responsible for the “wobbly-ness” of the character during animations. Since the modifier effectively locks the axis around a target, animations are going to look corrupted.
Again, this might also be part of the intended behaviour, but I find it confusing that the modifier is impacting some Axis other than the one I specified. Even when the Use Secondary Rotation
option is set to false
, it still cancels out all the rotations applied by the animation.
I also had to apply a small offset to compensate some “ugliness” caused by modified rotations not matching 100% the animation rotations, but the result is extremely satisfying.
I’d give 8.5/10 for this solution. Easy to setup. Easy to use and does not need any code other than the one you need to set a target (if you even need that in your case).
Custom SkeletonModifier Approach:
By far the best. From what I could see online you can pretty much apply any sort of custom behaviour through this low-ish level approach. Being low level it also implies a lot of (precise) engineering to achieve the wanted result, but it’s undeniable that this will yield the best looking output.
I have not tried this in my project. Definitely will keep it in mind for future tries/side-projects. But again, the barrier to start using this is very high (at least for me) so I don’t see this ever becoming extremely popular amongst hobbyist.
I’d give 10/10 for looks and 4/10 for accessibility. Definitely far from beginner friendly.