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

How to make the player face an object?

Asked by 6 years ago

I want to make the player forcefully face an NPC. What would I use in a script to pull this off?

0
You can do this by ajusting the CFrame of the HumanoidRootPart to the NPC's lookVector I think? Ziffixture 6913 — 6y
0
We can adjust the HumanoidRootPart's CFrame lookAt to the HumanoidRootPart of the NPC, or we can also use BodyGyros. Rheines 661 — 6y
0
So I was right? I just guessed::P Ziffixture 6913 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago

One of the CFrame constructors is CFrame.new(Vector3 pos, Vector3 lookAt) which constructs a CFrame at position pos oriented towards lookAt.

character:SetPrimaryPartCFrame(CFrame.new(character.PrimaryPart.Position, NPC.PrimaryPart.Position))

Since most likely you don't want the player to teleport elsewhere I keep the position the same. It just looks at the NPC now.


Don't forget to accept if this helps

0
Thanks! This worked perfectly. Starflyerz 44 — 6y
Ad

Answer this question