I've been testing my AI for a thief game. If he spots you, he'll look at you to investigate. But the AI's head doesn't move. How do I fix this??
My Code:
function lookAt(player) local is_in_front = NPC.PrimaryPart.CFrame:ToObjectSpace(player.Character.PrimaryPart.CFrame).Z < 0 if is_in_front then NPC.Head.CFrame = CFrame.new(NPC.Head.CFrame.p,(NPC.Head.CFrame.p - player.Character.Head.CFrame.p).Unit) end end
Change this:
NPC.Head.CFrame = CFrame.new(NPC.Head.CFrame.p-(NPC.Head.CFrame.p - player.Character.Head.CFrame.p).Unit) --// calling '.unit' isn't needed here since the 2nd part of the cframe constructor takes a world position not a direction as you have it
To either:
NPC.Head.CFrame = CFrame.new(NPC.Head.Position,player.Character.Head.Position) --// OR NPC.Head.CFrame = CFrame.lookat(NPC.Head.Position,player.Character.Head.Position)
hope this helps! :)