Quick! How to make an NPC's head turn behind the player?

My code :

local Players = game:GetService('Players')

local Scripts = script.Parent
local Configurations = Scripts.Parent

local Dummy = Configurations.Parent
local HumanoidRootPart = Dummy.PrimaryPart
local Torso = Dummy:WaitForChild('Torso')
local Head = Dummy:WaitForChild('Head')
local Neck = Torso.Neck

local Player = Players.LocalPlayer
local Character = Player.Character

while wait() do
	
	local headPos = Head.Position
	local lv = Torso.CFrame.LookVector
	local dist = (headPos-Character.Torso.Position).Magnitude
	local diff = headPos.Y-Character.Torso.Position.Y
	Neck.C0 = Neck.C0 * CFrame.Angles(-(math.atan(diff/dist)), -(((headPos- Character.Torso.Position).Unit):Cross(lv)).Y, 0)
end

This code does not work, and there are no errors in OutPut


I noted in which script I did this

Adjust the neck rotation

Neck.C0 = Neck.C0 * CFrame.Angles(-(math.atan(diff / dist)), math.pi, 0)

Not working :frowning: , there is no errors

Can you explain what you are trying to achieve? You have provided almost to no information on the issue and you can not expect us to help you solve it.

I want to make the Npc turn its head to the position where the player is. There are no errors in OutPut, but the script itself doesn’t work for some reason

You could use CFrame.lookAt().

oh,i try this. Wait, i reply to you

Nope, nothing happened.
Снимок

You could do this, and place it inside of the rig’s head:

local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()

while task.wait() do
	script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, player.Character.Head.Position)
end

Oh.

local Neck = -- Neck
local NeckC0 = Neck.C0

local function MoveHead()
	local headPosition = -- npc head position
	local playerPosition = -- players position
	local X,Y,_ = CFrame.new(headPosition,playerPosition)
	Neck.C0 = NeckC0 * CFrame.Angles(0,Y,0) * CFrame.Angles(X,0,0) -- Not joining them because of how CFrames work. If you do not want up and down movement remove the CFrame.Angles(X,0,0) part.
end
2 Likes

Try changing the orientation instead of the cframe

1 Like

I tried everything you sent me, but nothing worked(

Can anyone help me in the studio itself? Maybe you could do it

Maybe this would work?

Have you tried my way? At all??

Yes, i tried you script but he not work

It doesn’t work either, I checked on another rig but still no use either