0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ You're aware of Quaternion.LookRotation ? \$\endgroup\$
    – DMGregory
    Commented Aug 20, 2017 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
    Commented Aug 20, 2017 at 22:04

2 Answers 2

2
\$\begingroup\$

Maybe try this:

var dir = target.position - boneTransform.position;
var q = Quaternion.LookRotation ( dir );
anim.SetBoneLocalRotation(HumanBodyBones.Spine, q);
\$\endgroup\$
0
1
\$\begingroup\$

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.

\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .