Home Artists Posts Import Register

Content

Pawns. We love pawns. In Audience Anarchy, pawns are just kind of hanging around the place. But why? And what are they? And what is their purpose? In this blog post, I will answer none of these questions. Instead, here is a behind-the-scenes look at how the pawns work. Perhaps it could inspire you to add your own NPCs to your own worlds.

The first step is to have a model. This doesn't need to be a functional humanoid rig like most avatars, but an avatar model works just fine.

In Audience Anarchy, I use a variant of my Misfortune Pawn avatar, except with a few changes. The Crew Pawn has no eyeballs and the lower part of the robes have been sewn shut. I added headphones and a lanyard, and the sleeves are more T-shirt-like.

The next step is to create animations. For Audience Anarchy, I used a plugin called UMotion, which you can purchase on the Unity Asset Store, but you can also just create your animations in a third-party 3d modeling program like Blender and import the animation clips in your FBX (model) file.

Regardless of what program you use, you might find it useful to create an IK (Inverse Kinematics) rig, depending on what kind of animation you need to make. "Inverse kinematics" basically just means you can animate a character's limbs in a more intuitive way. With forward kinematics, you animate arms and legs by rotating the shoulder, knee, wrist, hip, knee, and ankle joints. With inverse kinematics, you basically just have to pose the wrists and ankles in space, and the algorithm animates the other joints for you.


UMotion includes an easy IK (Inverse Kinematics) rig setup wizard which creates 2 wrist goals and 2 ankle goals automatically. Since the pawn doesn't walk, I just pose the ankles and lock them in place on the ground for every animation.

Now it's time to create an idle animation. I start by blocking out a rough version of what I'm going for. I add keyframes for the pawn's pelvis bobbing up and down. Usually a 1 or 2 second loop is fine.  Make sure to copy-paste the first keyframe and last keyframe, so that the animation loops perfectly.

Then I add detail by rotating the pelvis, slightly offset from the bobbing up and down. You can also make the hands bob up and down to make it look a little more natural.

To make the pawn wave or do other gestures, I create a new clip, but copy the same starting frame so that the pose generally matches the idle loop.

After exporting the animations I can set up an animator with two states, the default loop, and the gesture which occasionally triggers when an animation trigger is activated. This is similar to avatar animations, but way simpler, since none of the avatar related components (menus, params, layers, etc) are needed.

The next step is to make the pawn actually play the gesture animation and a sound effect when the player approaches.
For the audio to play, a simple audio source is needed. The source is placed near the pawn's head and set to 3D instead of 2D.

A simple way to trigger the pawn's actions is with a trigger collider.
The pawn object in the world has two collider components attached. One is a solid capsule collider to prevent the player walking through it, and the second is a box collider the covers the nearby floor with "IsTrigger" enabled. Trigger colliders allow the player to pass through, and also send OnPlayerTriggerEnter events in Udon.

Then I can attach a new UdonBehaviour with code that handles the OnPlayerTriggerEnter event. I use UdonSharp but you can do something similar with Udon Graph if you prefer.

However, this will allow the player to spam the gesture animation. You can add a cooldown by remembering the current clock time whenever the player enters the collider, and only play the animation when X seconds has passed since the last time this happened.

The pawn should also use the AudioSource to play a random AudioClip. Using brackets next to the variable type means this is an AudioClip "array", so we can specify several possible AudioClips and choose a random one from the set.

The last step is to just drag and drop references so that the Udon script can actually interact with the Animator, AudioSource, and all the AudioClips we want to use.

When recording voice lines for pawns, I use a cheap text-to-speech program, record the output into a program called Audacity, apply a silly filter, and export each individual line as an .OGG audio file into the project folder. These clips can then be dragged and dropped into the AudioClips array easily.

That's pretty much it! The pawn lives!

This is just an example script I made from scratch to show you how to get started writing your own code, but you can actually do so much more with your NPCs. In Audience Anarchy, I have additional code which prevent repeating the same audio clip twice in a row (if possible), and makes the pawn smoothly turn and stare at you until you exit the collider.

What's next? Pawns that move around? Perhaps...

Files

Comments

Livedarkened

This would definitely make the scare world's more scary when making them move and chase target player.

Taco

WE LOVE PAWNS!!!