Help with Motor6D 'Neck' Position Pointing At My Character's Head Position [Looking for a quick and simple solution)

I’ve been fiddling with my script for numerous hours now trying to get an R6 humanoid rig’s neck motor to follow my character’s head position around in game.

To sum it up real quick, I’m trying to get an R6 humanoid’s head (the npc’s head) to follow my character’s head position around in game at all times. I’ve come close multiple times but this task has shaved valuable time away and I need to ask someone who is more knowledgeable than me.

Here is what I’ve been working with. I’ve researched countless times and I’m still unable to figure out why the head refuses to look at my character’s head. The code below rotates the head to the left about 90 degrees. It is not pointing towards the origin, I’ve tested it with different rotations and it turns its head to the left.

Looking for a simple and quick solution.
https://i.gyazo.com/1644f5be4392ee14d7d76d51d3dc3411.gif

wait(2.5)
local stare = game.Workspace.StaringEntity
local neck = stare.Torso.Neck
local char = game.Players.LocalPlayer.Character
local yOffset1 = neck.C1.Y
local yOffset0 = neck.C0.Y
neck.C1 = CFrame.new(0, yOffset1, 0) 
neck.C0 = CFrame.new(0, yOffset0, 0)
local direction = CFrame.lookAt(neck.C0.Position, char.Head.Position) --This is what should be controlling the npc's head to look directly at mine but doesn't work properly
game:GetService("RunService").RenderStepped:Connect(function()
	neck.C0 = direction
end)

This is probably super easy to accomplish but I have a very basic understanding of Motors, CFrames, etc.
Thanks for reading, I appreciate that.

You need to set the C0 only and not the C1. Then u can multiply that value by cframe.LookAt or whatevers.

So if what you are doing is trying to get the npc to look at your head, you could do something like this:

local yOffset = neck.C1.Y
local direction = CFrame.lookAt(neck.C0.Position, char.Head.Position)
local angle = math.atan2(direction.lookVector.X, direction.lookVector.Z)

game:GetService("RunService").RenderStepped:Connect(function()
    neck.C1 = (0, yOffset, 0) * CFrame.Angles(0, angle, 0)
end)

I haven’t confirmed if this works yet, I’ll update this post once I do.

Sorry for the late reply, I’ve just tested this and I get nearly the same result.

Unless there is supposed to something in front of “(0, yOffset, 0) * CFrame.Angles(0, angle, 0)”

Sorry for late notice, I’ve tried this before and you need to set the y values of the C1 and C0 of the motor otherwise the head snaps oddly.

This is what it looks like if you don’t set both the y values of C1 and C0 of the neck motor:
snapp.PNG

Ultimately, the head snaps widely in the direction that corresponds to C1 or C0. (For me at least)

Do ```Lua
local yOffset = neck.C0.Y
neck.C0 = CFrame.new(0,yOffset,0) * CFrame.new(playerPosition, Vector3.new(neck.C0.X,neck.C0.Y,neck.C0.Z))

Try, looking at the source code of the Motor6D manipulation within this project, it should be able to accomplish the task. Just remember that the C0 is relative the Part0 CFrame in object space while the CFrame.lookAt is relative to the world’s axis so you can’t directly set it the C0 of the motor6D.

1 Like

So here is the result with your code:
https://i.gyazo.com/1dc7683076b27b7ef94428479f61e68d.gif

However, I tweaked it a little and managed to make the head eject upward like a rocket:
https://i.gyazo.com/bddf48ebbfd92caeaa1ad7d9917034ee.gif

I will examine this and will let you know if I solve my problem. Thanks.

I’m back. I feel that this would work, however I’d much rather use something that is much simpler than this as I’m new to lua scripting and I like to understand how every script in my game works. However, I appreciate you sharing this as it likely will solve this issue and any issues like it.

If there is anyone reading this, definitely check this developer’s post.

If anyone knows a simpler way I can execute a simple npc head that looks at my head in a local script, let me know.

I have yet to find a solution. I will make another reply here once I figure out a simpler solution and have the time to do so.