# Smooth rotation for a bone?

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.LookAt(Target.transform.position);
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 *
YOUR_SMOOTHNESS_VALUE);
}


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.

• 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 ? – Omer May 13 '18 at 17:42
• Whats the error? – Vadim Tatarnikov May 13 '18 at 18:47
• Cannot implicitly convert type 'void' to 'UnityEngine.Quaternion' – Omer May 14 '18 at 3:07
• Perhaps try adding (Quaternion) before Chest.LookAt – Vadim Tatarnikov May 14 '18 at 11:02
• I did this but nothing change. Thank you Vadim for all what you did for me. – Omer May 14 '18 at 17:07