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

How to make a robot face a direction?

Asked by 6 years ago

Hey,

So I am working on a project and having NPC walk to points. There is a point where they all need to stand in one line, but one of them tends to be turned a little. Is there anyway I can rotate a NPC to face a direction? IE. Place a brick in front of them and they would all face that brick?

Thanks,

Anthony

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Well we can use cframe to make it point in a certain direction

First let's set our variables

local npc=workspace.npc
local lookat=workspace.Part

Here is how you make a cframe that points in a certain direction

local cf = CFrame.new(Vector3Position,Vector3Lookat)

Let's hook it up to your npc

local cf = CFrame.new(npc.HumanoidRootPart.Position,lookat.Position)

Now we can either set the cframe of the model's primary part if its set or we can add a bodygyro and add our variable to it

Bodygyro:

local bg=Instance.new("BodyGyro",npc.HumanoidRootPart)
bg.cframe=cf --bodygyro also uses cframe besides CFrame
--you may want to change other properties of the instances too

primarypart (if its set in the npcs)

npc:SetPrimaryPartCFrame(cf)

You could use one of these methods after your npc has reached its destination.

Ad

Answer this question