I want to character to be able to move in a direction and be able to aim to object in other direction. I use code below to control bone of a character:

anim.SetBoneLocalRotation(HumanBodyBones.Spine, Quaternion.Euler(...));

but I don't know what is the right way to rotate chest and spine of a character to make upper body aim to a position.

  • \$\begingroup\$ You're aware of Quaternion.LookRotation ? \$\endgroup\$ – DMGregory Aug 20 '17 at 21:14
  • \$\begingroup\$ @yes I'm aware. but bones not work much the same of transform. their movement and roatation is relative \$\endgroup\$ – virtouso Aug 20 '17 at 22:04

Maybe try this:

var dir = target.position - boneTransform.position;
var q = Quaternion.LookRotation ( dir );
anim.SetBoneLocalRotation(HumanBodyBones.Spine, q);

I don't know if this is the "right" way to do this, but whenever I had to manually rotate a bone, I would make a Transform boneToBeRotated member in the controlling class, and slot in whatever bone from the Scene hierarchy. Then you can manipulate it like any other transform, choosing rotation or localRotation as you see fit.

Oh, and with that method the rotation has to be done in LateUpdate, in order to override the normal animation rotation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.