[Solved]Make a NPC face a player

Hello ! , is there any possible ways to make a NPC face a Player ?
I tried to use Lookvector but it’s ReadOnly…
I have no clue at what i need to do and i can’t find any help anywhere…

Some help would be nice :slightly_smiling_face: .image

10 Likes

You can use CFrame.lookAt(at, lookAt) to get an NPC to look at a point.

-- in a loop,
NPC:SetPrimaryPartCFrame(CFrame.lookAt(
    -- start at the NPC's position
    NPC.HumanoidRootPart.Position,
    -- makes the NPC look at the player, but not move up and down
    Character.HumanoidRootPart.Position * Vector3.new(1,0,1)
        + NPC.HumanoidRootPart.Position * Vector3.new(0,1,0)
))

I hope that’s enough info.

Edit: this one is better cleaned up.

local NPCroot = NPC.HumanoidRootPart
local CharRoot = Character.HumanoidRootPart

NPC:SetPrimaryPartCFrame(CFrame.lookAt(
    NPCroot.Position,
    CharRoot.Position * Vector3.new(1, 0, 1)
        + NPCroot.Position * Vector3.new(0, 1, 0)
))
32 Likes

Thanks a lot ! i understand how it works now !

3 Likes

Using this function, the NPC cannot move using Humanoid:MoveTo() because it also sets the position of the CFrame. Is there anyway to only modify the orientation of the CFrame?

1 Like