# How to make npc look at player head (R6) with neck?

I spent a lot of time, but this so hard, there is no tutorial for r6 character. Please, if you know how to do this , send me script then, thx. (I need look only in x direction and move only head). Target - CFrame.new(npc.Character.Torso.Position,LocalPlayer.Character.Torso.Position)
npc.Character.Torso.Neck.C0 = ?

2 Likes

Get ready for some painful math and a ton of assumptions. I wrote this for a custom character but the math still applies.

``````local headPos = Player.Character.Head.Position
local lv= Player.Character.Torso.CFrame.LookVector
NECK = NECK or Neck.C0 --Grab the original position once if you don't already have it

Neck.C0 = NECK * CFrame.Angles(-(math.atan(diff/dist)), -(((headPos-point).Unit):Cross(lv)).Y, 0)``````
3 Likes

Yeah! Thanks, but this change head rotation to z for me, how to change to x?
Code:

``````        local headPos = npc.Head.Position
local lv = npc.Torso.CFrame.LookVector
NECK = npc.NeckSave.Value
npc.Torso.Neck.C0 = NECK * CFrame.Angles(-(math.atan(diff/dist)), -(((headPos-LocalPlayer.Character.Torso.Position).Unit):Cross(lv)).Y, 0)
``````

Oops I left out what the â€śpointâ€ť variable is meant to be. You have it as torso but it should be the following:

`point = camera.CFrame.Position + camera.CFrame.LookVector * 10000`

I donâ€™t understand what is point for me, I tried this (I need npc look at player torso):

``````		local point = CFrame.new(npc.Torso.Position,LocalPlayer.Character.Torso.Position).Position
local lv = npc.Torso.CFrame.LookVector
NECK = npc.NeckSave.Value
npc.Torso.Neck.C0 = NECK * CFrame.Angles(-(math.atan(diff/dist)), -(((headPos-point).Unit):Cross(lv)).Y, 0)
``````

Ahh my mistake the point I gave you was for your own character. In this case what you had before was correct, itâ€™s just the position of the target you want the npc to look at. As for the rotation axis issue, the C0 must be set up differently that I have it. Try switching the order of the CFrame.Angles() to find the right axis, itâ€™s a bit tricky to tell which one you need.

Ok,thanks, i will reply soon .

Do you want it to only look at the player from the playerâ€™s perspective or from the entire servers perspective?

only from local player point of view

Yeah, i did it. Big thanks to Barothoth.This is code:

``````        local headPos = npc.Head.Position
local lv = npc.Torso.CFrame.LookVector