Skip to main content

Head and Eye Movement

By default, avatars generated in the studio support basic head movements (e.g., looking at the player). If you want more detailed head and eye movements (e.g., nodding, blinking, etc.), then it is recommend that you use Realistic Eye Movements as we have already prepared a .json file for loading head/eye related parameters for Realistic Eye Movement. It is located at Assets/Inworld.AI/Resources/Animations/RPMREM.json.

1. Preparation

Once the package has been imported, find the prefab InworldCharacter, and add the components LookTargetController and EyeAndHeadAnimator.

Head01

In the Inworld AI Unity SDK, after a .glb model is dragged into the UnityScene, it will trigger events that lead to IAvatarLoader::ConfigureModel().

By default, the IAvatarLoader is GLTFAvatarLoader, and it will call IEyeHeadAnimLoader::SetupHeadMovement() to set up head and eye movement if it exists.

HeadStructure

Let's create our own integrations.

2. Implement Interfaces

Create a Monobehavior class that inherits IEyeHeadAnimLoader. You can name it whatever you want, e.g., InworldHeadAnim.

Head02

Let's load that by implementing the interface function.

namespace Inworld.Model.Sample
{
public class InworldEyeHeadLoader : MonoBehaviour, IEyeHeadAnimLoader
{
[SerializeField] string m_HeadEyeAsset = "Animations/REMRPM";

public void SetupHeadMovement(GameObject avatar)
{
EyeAndHeadAnimator eyeHead = avatar.GetComponent<EyeAndHeadAnimator>();
if (!eyeHead)
return;
TextAsset textAsset = Resources.Load<TextAsset>(m_HeadEyeAsset);
if (!textAsset)
return;
EyeAndHeadAnimatorForSerialization import = JsonUtility.FromJson<EyeAndHeadAnimatorForSerialization>(textAsset.text);
eyeHead.headBoneNonMecanim = Utils.GetTransformFromPath(avatar.transform, import.headBonePath);
eyeHead.ImportFromJson(textAsset.text);
}
}
}

⚠️ Note: We need to set the value of headBoneNonMecanism because the EyeHeadAnimator has not been fully initialized yet, i.e., Transform is null. We need to pass the avatar's transform, otherwise it will throw an error.

3. Create and configure prefabs

  1. Create an empty gameObject. Attach the script InworldHeadAnim that you just implemented.

  2. Create a prefab for that object.

  3. Delete the object from the scene.

  4. Find the GLTFAvatarLoader prefab in your Assets folder, and drag the prefab that you created into the GLTFAvatarLoader's Head Animation.

HeadPrefab

4. Runtime

You can test your avatar's head animation. Once the avatar has been dragged into the scene, check if LookTargetController and EyeAndHeadAnimator exist, and whether the data for the head and eyes has been set.

LipFinalPng

You can adjust the parameters and observe differences in nodding and blinking behavior. Check the website for more information.

LipFinal