Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make an NPC head turn towards a player?

Asked by 6 years ago

I used some guy's Technique to do this, however, He has a part when it said:

                        --look at character until it leaves or goes behind
                        repeat
                            p = head.Position
                            pos = ppart.Position
                            head.CFrame = CFrame.new(p,pos)
                            wait(1/20)
                        until ( (pos-p).magnitude > radius ) or ( rotationDifference(cf , head.CFrame ) > 1.25 )
                        head.CFrame = (cf-cf.p)+p --old rotation
                        break
                    end

And I didn't want it to Stop when I go behind. So can any of you guys please help me?

--ChannelRansom_Yt

0
pos = ppart.Position? What's ppart? mixgingengerina10 223 — 6y
0
Body gyro INOOBE_YT 387 — 6y
0
@ChannelRansom_YT what's your problem here? I don't understand it. mixgingengerina10 223 — 6y

1 answer

Log in to vote
0
Answered by
SCP774 191
6 years ago
Edited 6 years ago

It's actually really easy, there is a hidden argument in CFrame.new, called "lookAt".

Here's an example how to do it:

while wait() do
    head.CFrame = CFrame.new(Vector3.new(head.Position.X, head.Position.Y, head.Position.Z), Vector3.new(targetPlayer.HumanoidRootPart.X, targetPlayer.HumanoidRootPart.Y, targetPlayer.HumanoidRootPart.Z))
end

The NPC's head will now "look at" the desired player's HumanoidRootPart constantly.

Ad

Answer this question