NPC looking at player issue

I am remaking PARTY.exe by 8DSKan, and I made this NPC that will look at you but something’s off.


As you can see he has his head connected to this cyan ball
image
Which means he should move his head like this:


But instead he completely ignores the attachment and moves it like its in the center

Here’s the script:

	game:GetService('RunService').Heartbeat:Connect(function(delta)
		local Plr,Char = GetNearestPlayer(Torso.Position, math.huge)
		
		if Plr then
			if Char then
				Neck.C0 = Neck.Part0.CFrame:Inverse()*CFrame.lookAt(Neck.Part1.Position, Char.Head.Position) * Neck.C1
			end
		end
	end)

I’d like some help

1 Like
local HumanoidRootPart = -- hrp of npc
Neck.C0 = HumanoidRootPart:ToObjectSpace(CFrame.new(HumanoidRootPart.Position,Char.Head.Position))*NeckC0Offset -- the base neck c0 offset
Neck.C0 = NPC.HumanoidRootPart.CFrame:ToObjectSpace(CFrame.new(NPC.HumanoidRootPart.Position,Char.Head.Position))*Neck.C0

uhhh

2 Likes

ah you need to make a variable above the runservice or while loop titled: NeckC0Offset and replace the last Neck.C0 with it.


better, but still behaves kinda weird

oh well its something similar to it. i had the script but now its gone.

or

local olneckc0 = Neck.C0-Vector3.new(0,1,0)
Neck.C0 = NPC.HumanoidRootPart.CFrame:ToObjectSpace(CFrame.new(NPC.HumanoidRootPart.Position+Vector3.new(0,1,0),Char.Head.Position))*olneckc0
1 Like

whenever i modify motor6d’s i usually do something like this, maybe it’ll work

local target:BasePart
local npc:Model
local head:BasePart=npc.Head
local motor:Motor6D=npc.Torso.Neck
local originalC0:CFrame=motor.C0
game:GetService("RunService").Heartbeat:Connect(function()
	motor.C0=motor.C0:Lerp(originalC0*CFrame.new(head.Position,target.Poistion),1)
end)

thats like doing
originalC0*CFrame.new(head.Position,target.Position)

it usually works for me. Putting it in a lerp just helps if you want to ease the head turning.
if it doesn’t work try removing the new cframes position

local cframeTo=CFrame.new(head.Position,target.Position)
cframeTo-=cframeTo.Position

Thank you so much!!!

character limit

No problem! I knew I was missing something just didn’t know what.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.