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

How would I rotate a model to match a part's position?

Asked by 5 years ago

The model is an NPC that needs to rotate/face a second NPC's position when the second NPC touches the first.

I've used this code down below, but it isn't entirely accurate and makes the model spin.

local model = script.Parent.Parent.Parent
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name == "NPC"  then
        local position = model.HumanoidRootPart.CFrame
        local torso = hit.Parent.Torso
        model:SetPrimaryPartCFrame(position * (torso.CFrame - torso.Position))
    end
end)

Any help is appreciated.

0
use for i,v in pairs(getchildren()) do SunxLightz 30 — 5y
1
I've discovered this a few months back, and it should help. https://developer.roblox.com/api-reference/class/AlignOrientation TheePBHST 154 — 5y
0
this is another helpful link regarding AlignOrientation https://devforum.roblox.com/t/new-body-movers/33652 CardboardedCharacter 53 — 5y

Answer this question