How do I make an NPC look at something?

Hello!

So basically in my fnaf fangame, I have a light mechanic. Basically at one moment, a character will slowly go in front of the office and go to a vent.

Now there’s a mechanic of a light, if we flashed it, the character stops.

And basically I got things correctly, but as the title says, I want to know how to make the npc look at something.

I thought of maybe turning the HumanoidRootPart to a rotation but I am pretty sure there’s another way.

So here’s my script

local sun = script.Parent

local humanoid = sun.Humanoid

local Humpart = script.Parent.HumanoidRootPart


humanoid:MoveTo(workspace.FrontOfOffice.Position)
humanoid.MoveToFinished:Wait()
humanoid:MoveTo(workspace.FrontOfOffice2.Position)
humanoid.MoveToFinished:Wait()
humanoid.WalkSpeed = 1
local WalkAnim = script.Parent.Animate.walk.WalkAnim


humanoid:MoveTo(workspace.TOGLASS.Position)
local LC = game.Workspace.LightConditions

LC.Flashing:GetPropertyChangedSignal("Value"):Connect(function()
	humanoid:MoveTo(Humpart.Position)
	print("OH NO I HAVE BEEN FLASHED!")
--Now we turn to something
	wait(5)
	humanoid:MoveTo(workspace.TOGLASS.Position)
    end)


humanoid.MoveToFinished:Wait()

I added this:
local TweenService = game:GetService(“TweenService”)

local Info = TweenInfo.new(

1,

Enum.EasingStyle.Back,

Enum.EasingDirection.Out,

0,

false

)

local Light = game.Workspace.LightThing.Light.LightStuff

local Goals = {

Orientation = --Look at the light

}

It’s basically TweenService but now I do not know how I can make the look part.

There’s a thing you can do with CFrame which is really simple. Here is the code below:

local Part = -- Make this the head.
local Part2 = -- Make this the object you want the NPC to look at.
while wait() do 
      Part.CFrame = CFrame.new(Part.Position, Part2.Position) 
end

To make it understandable, the part you’re getting the CFrame of is the part that’ll be looking at something, you then need to create a new CFrame, the first parameter is the position of what is going to be looking at something. The second parameter will be the part that’s getting looked at. Hope this helps out!

2 Likes