Why does lookAt attract a r6 character?

For some reason lookAt starts pulling the player to the NPC instead of the player just looking at the NPC

This happens when the player is playing an animation

function Combat:lookAt(Target : Model)
	local char = player.Character
	if not char then
		return
	end

	if not self.Connections['lookAt'] then
		self.Connections['lookAt'] = RunService.Heartbeat:Connect(function(deltaTime: number) 
			local charPos = char:GetPivot().Position
			local TargetPos = Target:GetPivot().Position
			char:PivotTo(CFrame.lookAt(charPos, Vector3.new(TargetPos.X,charPos.Y,TargetPos.Z)))
			
		end)
	end
end

I found that sometimes pivot position is mot the same as root part. Try using root part.

Also might be due to client or server differences. Something to think about.

i’ll try use root part,but same
and yes its client

Got it, try using root.CFrame instead of :PivotTo()

1 Like

Maybe try use

char:PivotTo(CFrame.new(charPos, Vector3.new(TargetPos.X,charPos.Y,TargetPos.Z)))

Instead of

char:PivotTo(CFrame.lookAt(charPos, Vector3.new(TargetPos.X,charPos.Y,TargetPos.Z)))

I tried that, too, but it doesn’t make any difference xd