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.
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.
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.
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.