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
.
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.
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
.
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 theEyeHeadAnimator
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
Create an empty
gameObject
. Attach the scriptInworldHeadAnim
that you just implemented.Create a prefab for that object.
Delete the object from the scene.
Find the
GLTFAvatarLoader
prefab in yourAssets
folder, and drag the prefab that you created into theGLTFAvatarLoader
'sHead Animation
.
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.
You can adjust the parameters and observe differences in nodding and blinking behavior. Check the website for more information.