• News

• Industries

• Learning & Support

• Community

• Marketplace

# Have NPCs rotate head towards player in range?

Hey everyone,

gonna ask in this section as I believe it is something that needs to be done in the animation blueprint and I can’t seem to find any tutorial around about it.

How do you actually implement a mechanic that has NPCs head rotate towards the player’s face when this player comes into a certain range of the NPC? It’s a mechanic that tons of NPC have been having in games for ages but I can’t really find any tutorial about it.

Thanks to all those who will reply!

In the animation BP, you can use for example the “Transform (modify) Bone” node to rotate the head or the neck bone towards your target:

](filedata/fetch?id=1817930&d=1601645664)

Ok thanks. But how would I go about implementing it on a npc? Also is there an optimized way to do it without a tick?

Just have a collider to check when player in range. If so, then set the target and:

Then it’s just a question of reading that rotation in the animation BP and passing it to the animgraph.

As long there aren’t hundreds of NPCs in range, the performance hit of using Tick won’t be significant.

It’s working quite well, thanks so much man! Just a couple more things if you don’t mind.

1 - How can I set it up so that the NPC will look at the face? At the moment it seems to look somewhere around the pelvis.

2 - How can I clamp the rotation of the head so that the NPC doesn’t go in a sort of kid from the exorcist mode?

As for 1, you just need to add a z value to the target of look at.

As for 2, you can use the dot product between the head rotation and the character.

The head will only turn if the character is between 90 and -90º in relation to the head (for lesser/higher angles, change the comparation value), . Once it crosses that limit, the head snaps to its normal position (you can use interp to make it more natural).

PS: I sure there is an easier way to do all this, but I’m to lazy to think about it any further.

Thanks a lot I will look into it!

If its an NPC I would probably use blackboard and pawn sensing.
not that all this stuff above isn’t good too, its just unnecessary.

You can get the rotation with a simple lookat node.

You can use blackboard to set the value automatically based on sensing.

I’m not sure when ill have the time, but I do need to do it so I may film a short tutorial on it.

I was actually thinking of using pawn sensing instead of the box collision, but I wouldn’t be quite sure how to do it, I’m only still a beginner lol.

Should you ever do a tutorial on that please post it here as I believe many people would be interested in this.