#Can you control specific limbs of an armature through code?

1 messages · Page 1 of 1 (latest)

ancient cave
#

Hi all! 🙂
I'm trying to setup a player controller in Unity, mixing animators and code.
I have a pre animated 3D dude (from the asset store), with idle, walk and run animations. What I want to do is use the premade animation for the waist down, and let the player control the torso and arms with mouse and keys. Imagine you're about to walk the plank with your back unnaturally upright, and you can move the mouse left and right to rotate the spine in a Z axis, (i.e. leaning to the sides) and can lower or raise your arms, (or even bring them forward), with a different input, maybe Q/E or mouse forward/backward.

The thing is I'm trying to find documentation or tutorials for this, and all I can find are tutorial for fully animatin with the Animator component, and that's not what I want nor need.
How can I access specific parts of the armature in order to rotate them through code?
Here's the setup that I have:

#

I can't post images directly, so I hosted it online:
ibb. co/ SHTcNrb

#

It's a 3D character with an Animator, that has an AnimatorController with 3 animations, idle, walk, run.
The animations are controlled using the Animator's state machine through code, like
animator.SetBool("run", cc.velocity.magnitude > minimumSpeed );

The armature has a gazillion bones. I deleted the animations points from the spine up, so only hip below is animated. Currently the model is walking around T-posing. The project is already setup to take (old input system) inputs with WASD and mouse, and the camera is setup to an almost fixed POV so the character moves around and rotates like in any fixed-camera game.

hasty turtle
#

If you are working with a humanoid armature, you can use Avatar Masks to control which limbs are affected by the animations.

Aside from that, you can also simply override changes made by animations through code.
However, since the normal Update (and afaik also LateUpdate) loops run before the Animator updates, you would need to use OnAnimatorIK instead.

ancient cave
#

I mean not those exact words but that's pretty much the idea