Head-turning NPCs

I’d like to look into this, if nobody’s already working on it: Codecks

Also let me know if there’s anything I should know beyond what’s on the card!

1 Like

Nothing that I can think of. Are you familiar with Animation Rigging?

Nope! Yesterday I got to a point where I had a MultiAimConstraint operating on a townsfolk’s head to make him look at a rock or something as he walked around, but there was some screwiness with the axes and he kept turning his head so his left ear was pointing at the aim target, not his face. :frowning:

And I’m not sure if that’s the right approach anyway because I can’t seem to update the MultiAimConstraint’s source object at runtime, and there’s not a player object in the scene itself to link it to in the editor…

So yeah, bit of a learning curve. Any guidance would be welcome. :slight_smile:

The sequence of steps as I currently understand it:

  • Add a Rig Builder to the top-level townsfolk object, on the same level as the Animator
  • Add a child with a Rig component and tell the Rig Builder to use it
  • Add children to the object with the Rig and give them Constraint components set up to [???]
  • Use scripts to control the behavior of the Constraints by [???]

Update: I figured out what I was doing wrong with the axes, and I can now get a villager to properly look in the direction of something. :slight_smile:

The constraints of AnimationRigging activate (on Start I think) and create a job with all the parameters including the target Transform, so that the constraint can run multi-threaded. Once the job has been created, changing them from the Inspector has no effect, unless you call some API to recreate the job.

One thing you can do is to add a child object as the target, and have a script (maybe a StateMachine action…?) update this object’s position to the character head. Then the constraint would rotate the bone appropriately.

Ok, that all makes sense! Thanks.

In the meantime, I’ve figured out how to constrain multiple nodes so that the villager twists his upper body a bit to look at things, rather than just eerily turning his head back and forth.

1 Like

Update: I’ve got the villager looking at the player when the player is in his field of vision, as defined by a trigger zone. The problem now is that he turns his head instantly when the player enters/exits the zone.

https://vimeo.com/569960382

1 Like

Okay, really happy with where this is at now. Gonna call it a day. :slight_smile:

https://vimeo.com/569991018

5 Likes

Nice! :slight_smile:
You could probably make the head turn a bit slower or make the trigger less generous. But it’s already looking super cool!

I actually made a video on the subject last year, if you want to go a bit deeper on Animation Rigging (although some basics you already covered):

Also, just noticed that Matt Gambell from Game Dev Guide posted a video related to this, if you’re interested. I think he talks more about using it with Timeline, and it could be that he doesn’t use Unity’s Animation Rigging package but a custom one (haven’t watched it through):

2 Likes