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 6 years ago
Edited 6 years ago

Hello there.

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

Here is my script:

local runService = game:GetService("RunService")
local NPC = script.Parent

function move()
    local neck = NPC.Head.Neck -- 'Neck' is a Motor6D
    local target = workspace.NoBootAvailable.Head
    local lookAt = CFrame.new(neck.C1.p, target.CFrame.p)

    neck.C1 = lookAt
end

runService: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 6 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.

local 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 6 years ago

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

Answer this question