I’m creating an npc system currently, and I want the npc to look at the player smoothly at all times
-
What is the issue? Include screenshots / videos if possible!
My problem is that the npc only faces the player’s attachment look vector and not the actual player. I suspect this is caused from the orientation of the attachment but idk how I can fix this.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
below is the code for how im handling the align orientation,
local function CreateBodyMovers(npcModel: Model)
local npcRoot = npcModel:WaitForChild("HumanoidRootPart")
-- Create or get an attachment on the NPC's root
local npcAttachment = npcRoot:FindFirstChild("OrientationAttachment")
if not npcAttachment then
npcAttachment = Instance.new("Attachment")
npcAttachment.Name = "OrientationAttachment"
npcAttachment.Parent = npcRoot
npcAttachment.Position = Vector3.new(0, 0, 0)
end
-- Create or get an attachment on the player's HRP (assume HRP is a global or passed reference)
local playerAttachment = HRP:FindFirstChild("OrientationAttachment")
if not playerAttachment then
playerAttachment = Instance.new("Attachment")
playerAttachment.Name = "OrientationAttachment"
playerAttachment.Parent = HRP
playerAttachment.Position = Vector3.new(0, 0, 0)
end
-- Create the AlignOrientation constraint on the NPC's root part
local alignOri = Instance.new("AlignOrientation")
alignOri.Name = "AlignOrientation"
alignOri.Parent = npcRoot
alignOri.Mode = Enum.OrientationAlignmentMode.TwoAttachment
alignOri.Attachment0 = npcAttachment
alignOri.Attachment1 = playerAttachment
alignOri.MaxTorque = 1e5
alignOri.Responsiveness = 8
alignOri.RigidityEnabled = false
alignOri.LookAtPosition = Vector3.new(HRP.Position.X,HRP.Position.Y,HRP.Position.Z)
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.