How to make npc turn to the direction that the player character is facing at?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    As the title said, I want to make the NPC turn to the direction hat that the player character is facing at

  2. What is the issue? Include screenshots / videos if possible!
    The issue is I don’t know how to make it.
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I am looking for solution in Devforum

Thank you

1 Like

You should look into these articles:
https://create.roblox.com/docs/building-and-visuals/studio-modeling/cframes
https://create.roblox.com/docs/building-and-visuals/studio-modeling/cframes#facing-toward-a-point

This might do you the trick though:

local npc = script.Parent

local function TurnToPlayer(player)
    local character = player.Character
    local primary = character.PrimaryPart
    local piv = npc:GetPivot().Position
    local designated = Vector3.new(primary.Position.X, piv.Y, primary.Position.Z)
    npc:PivotTo(CFrame.new(npc:GetPivot, designated))
end

to make the NPC smoothly look at the player, implement roblox’s TweenService!

if you need anymore help feel free to reply to this post

1 Like