
Top 20 Mobile Rendering Mistakes in Unity (And How to Avoid Them)
August 4, 2026
Unity Book Viewer Setup Guide | free unity asset | Unity Book Asset
August 4, 2026Head tracking makes characters feel alive.
Instead of staring forward like robots, they can smoothly look at the player, a target, or any object in the scene.
This guide shows you the simplest, cleanest, and most universal method to add head tracking to ANY Humanoid character in Unity — without breaking animations.
1. What Is Head Tracking?
Head tracking means rotating the character’s head bone so it looks at a target.
Unity gives us a built-in API for this: OnAnimatorIK().
Using IK ensures:
- Animations still play normally
- The head rotates only when allowed
- Smooth interpolation
- No need to modify animations
2. Requirements
- A character with Humanoid rig
- An Animator component
- A target Transform (player, object, enemy, etc.)
3. Basic Head Tracking Script (Clean & Universal)
This script uses Unity’s IK system to rotate the head toward a target.
using UnityEngine;
public class HeadTracking : MonoBehaviour
{
public Transform target; // Object to look at
public float weight = 1.0f; // Strength of head rotation
public float smooth = 5.0f; // Smooth interpolation
public float maxAngle = 70f; // Clamp angle for realism
private Animator animator;
private float currentWeight;
void Start()
{
animator = GetComponent<Animator>();
}
void OnAnimatorIK(int layerIndex)
{
if (target == null)
{
currentWeight = Mathf.Lerp(currentWeight, 0, Time.deltaTime * smooth);
animator.SetLookAtWeight(currentWeight);
return;
}
// Smooth blend
currentWeight = Mathf.Lerp(currentWeight, weight, Time.deltaTime * smooth);
// Distance check
float dist = Vector3.Distance(transform.position, target.position);
if (dist > 20f) currentWeight = 0; // too far to track
// Clamp angle
Vector3 dir = target.position - transform.position;
float angle = Vector3.Angle(transform.forward, dir);
if (angle > maxAngle) currentWeight = 0;
animator.SetLookAtWeight(currentWeight, 0.2f, 1f, 1f, 0.5f);
animator.SetLookAtPosition(target.position);
}
}
Attach this script to your character root (the object with the Animator).
4. Best Settings for Realistic Head Motion
- weight: 0.5–1.0 for subtle or strong tracking
- smooth: 4–8 for natural movement
- maxAngle: 60–80 degrees (humans cannot turn heads 150°!)
- Distance limit: disable tracking if target is too far
5. How to Make Eyes Track as Well
You can add eye tracking using the same IK weight system:
animator.SetLookAtWeight(currentWeight, bodyWeight:0.3f, headWeight:1f, eyesWeight:1f);
This allows the eyes to follow the target independently of the head.
6. Adding a “Look-At Target” on Runtime
For AI characters, you can dynamically set a target:
public void LookAt(Transform t)
{
target = t;
}
public void StopLooking()
{
target = null;
}
This is perfect for:
- NPCs looking at the player
- Enemies tracking the hero
- Characters reacting to objects
- Cinematic interactions
7. Prevent Head Tracking During Certain Animations
Disable tracking during attacks or special moves:
bool canTrack = !animator.GetCurrentAnimatorStateInfo(0).IsTag("NoTrack");
if (!canTrack)
currentWeight = 0;
Just add the tag NoTrack to animations where head movement should freeze.
8. Optional: Add Smoother Target Following
Instead of snapping directly to the target, follow a smoothed hidden target:
private Vector3 smoothPos;
void Update()
{
if (target != null)
smoothPos = Vector3.Lerp(smoothPos, target.position, Time.deltaTime * 8f);
}
This gives extremely natural character behavior, like AAA NPCs.
9. Debugging Tips
- If head doesn’t move → ensure Animator has “IK Pass” enabled.
- If character snaps → reduce weight.
- If head turns too far → reduce maxAngle.
- If performance drops → IK cost is minimal; problem is elsewhere.
Conclusion
Adding head tracking to any Unity character is surprisingly simple thanks to Unity’s IK system.
With only a few lines of code, your NPCs or player characters can smoothly follow targets, look at the player, react to objects, and feel dramatically more alive.
This technique works with ALL Humanoid characters, Mixamo rigs, URP/Built‑in/ HDRP, and any gameplay style.









