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

How do you make a character rotate their heads towards a point?

Asked by 7 years ago
Edited 7 years ago

Hello there.

I'm trying out Motor6Ds to make my NPC's Head face towards me.

Here is my script:

01local runService = game:GetService("RunService")
02local NPC = script.Parent
03 
04function move()
05    local neck = NPC.Head.Neck -- 'Neck' is a Motor6D
06    local target = workspace.NoBootAvailable.Head
07    local lookAt = CFrame.new(neck.C1.p, target.CFrame.p)
08 
09    neck.C1 = lookAt
10end
11 
12runService:BindToRenderStep(move)

The problem is that the NPC's Head wont face towards me. Is there any reason why?

2 answers

Log in to vote
0
Answered by 7 years ago

Luckily I've been playing around with Motor6Ds and I've done something like this recently. You are very close to making this work but, what I found out about rotating parts(motor6Ds) of a already rotating model(NPC) is the orientation of the vector you want the limb to point to gets really miss lead with all these different oriented parts/models. So I had to use "toObjectSpace" to fix the problem. I don't completely understand it but, what I can figure is that it puts the vector into it's own space instead of the world space. The line below is what I did to fix my problem hopefully it will fix yours. If not, try playing around with the function.

1local lookAt = (NPC.HumanoidRootPart.CFrame:toObjectSpace(target.CFrame.p))

sorry for the ugly explanation, but I hope it helps :)

Ad
Log in to vote
0
Answered by 7 years ago

Still no luck, even if I convert it to World Space.

Answer this question