Using motor6ds to rotate an NPC

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 =, 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))

You notice how the shoulder points toward me on one

And the torso on the other

1 Like

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.

I’ve fixed the code block. The second .gif is the correct one.

When its rotated 90 degrees to the left it is facing the right way. The issue is really in the conversation from object space to world space.

1 Like

Figured it out, thanks for the attempt to help

You can mark a solution by clicking the box with a checkmark rather than putting “SOLVED” it is easier and is more uniform.

Please also add a description of what you did to fix it, it might help future forum users if they are having a similar issue and end up on this post.

1 Like

I figured out that the only thing I really needed was the RealPos from this article to get it to work out. It works perfectly now!

Here’s the article:

1 Like