I’m trying to use Motor6Ds already placed in a character model to rotate an NPC to follow a players movement. I’ve successfully gotten this testing script to follow myself(Protracted) around the map. When its facing in one direction. If I rotate the NPC any other way it doesn’t work. I’ve uploaded two videos to show the working version and the non working version from when I rotate the NPC.
Here is what I have so far
local rig = game.ReplicatedStorage.yes
rig.Parent = workspace
while game:GetService("RunService").Stepped:Wait() do
local lookAt = CFrame.new(rig.HumanoidRootPart.Position, workspace:WaitForChild("Protracted").UpperTorso.Position) - rig.HumanoidRootPart.Position
rig.UpperTorso.Waist.Transform = rig.UpperTorso.Waist.Transform:ToObjectSpace(rig.UpperTorso.Waist.Transform * lookAt)
print(rig.UpperTorso.Waist.Transform:ToObjectSpace(rig.UpperTorso.Waist.Transform * lookAt))
end
This post is a little confusing, so I’m not sure I can provide a response. Which GIF is the working one, which one doesn’t work and what are you trying to achieve? Also, if you could enclose your code in a codeblock with indentation, that would make the post easier to read (“```lua” at the top and “```” at the bottom of your code).
If I’m understanding correctly though, what you’re trying to accomplish is a character’s upper body rotating to face a nearby character. The issue is that when they’re rotated in one direction they face the character sideways, but if they’re rotated 90 degrees from that then they properly face the character… right?
In that case, I think I have an idea of how to fix it, though I don’t work with the CFrames I dread so I wouldn’t know completely. I think what you want to achieve here is to somehow make your rotations relative to the NPC so they essentially don’t change with rotations. I don’t know.