I'm trying to make my character bone "chest" rotate smoothly when face enemy and get back to his stand. Can anyone help me with this ?

public Transform Target;
public Vector3 Offset;

Animator anim;
Transform chest;

public float rotation_speed;
public bool aim_at_traget = false;

void Start()
    anim = GetComponent<Animator>();
    chest = anim.GetBoneTransform(HumanBodyBones.Chest);

void LateUpdate()
    if (aim_at_traget == true) {
    // smooth rotation to face target
    chest.rotation = chest.rotation * Quaternion.Euler(Offset);
    else {
        // get back to you stand smoothly 

In LateUpdate(), I would change the code to be this:

if(aim_at_target == true) {
   Quaternion rot = Quaternion.LookRotation(Target.transform.position - transform.position);
   chest.rotation = Quaternion.Slerp(chest.rotation, rot, Time.deltaTime * 

Not sure what 'Quaternion.Euler(Offset)' is exactly but you probably can just multiply it in the second parameter of Quaternion.Slerp().

I did not test this, so may have a small mistake, I'm just giving you an idea to proceed and make it a smooth rotation.

| improve this answer | |
  • \$\begingroup\$ Thank you for your respond. you code give me error on first line. I tried to do what you said. Using Slerp but still I can't see smooth movement. What else you advice me to do ? \$\endgroup\$ – Omer May 13 '18 at 17:42
  • \$\begingroup\$ Whats the error? \$\endgroup\$ – Vadim Tatarnikov May 13 '18 at 18:47
  • \$\begingroup\$ Cannot implicitly convert type 'void' to 'UnityEngine.Quaternion' \$\endgroup\$ – Omer May 14 '18 at 3:07
  • \$\begingroup\$ Perhaps try adding (Quaternion) before Chest.LookAt \$\endgroup\$ – Vadim Tatarnikov May 14 '18 at 11:02
  • \$\begingroup\$ I did this but nothing change. Thank you Vadim for all what you did for me. \$\endgroup\$ – Omer May 14 '18 at 17:07

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.