I have an npc that I want to face my character.
I found a method of doing this but its not quite working right:
function aim()
local chunk = math.rad(90)
if target then
local lookvec = target.CFrame.LookVector
local angle = -math.atan2(lookvec.Z,lookvec.X) + chunk
script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Center.Position) * CFrame.Angles(0,angle,0))
end
end
sometimes the npc looks at my character, and sometimes its looking in the wrong direction.
whats going on and what do I do to fix this?