(help) How do i make animations have no effect when i use Motor6d to aim

I want to move the npc to look at the player but when animation is played the head is being affected by the animation since my idle animation has the head rotated slightly left.

llocal ha = script.Parent.Head.Neck
local aim = script.Parent.Humanoid.Animator:LoadAnimation(script.Aim)
script.Parent.Humanoid.Animator:LoadAnimation(script.idle):Play()
aim:Play()
aim:AdjustSpeed(0.01)
local ra = script.Parent.RightUpperArm.RightShoulder
local ha = script.Parent.Head.Neck
local raC0 = ra.C0
local haC0 = ha.C0
local function calculateVerticalAngle(vector1, vector2)
	-- Normalize the vectors
	local v1 = vector1.Unit
	local v2 = vector2.Unit

	-- Calculate the dot product
	local dotProduct = v1:Dot(v2)

	-- Calculate the angle in radians
	local angleRadians = math.acos(dotProduct)

	-- Convert the angle to degrees
	local angleDegrees = math.deg(angleRadians)

	return angleRadians
end
game:GetService("RunService").PreRender:Connect(function()
	local ang =( script.Parent.HumanoidRootPart.Position.Y-workspace.targetB.Position.Y/math.abs(script.Parent.HumanoidRootPart.Position.Y-workspace.targetB.Position.Y))  *calculateVerticalAngle(script.Parent.HumanoidRootPart.CFrame.RightVector, workspace.targetB.Position-script.Parent.HumanoidRootPart.Position)
	--		aim.TimePosition = script.Parent.Value.Value
	local s = vector.angle(script.Parent.HumanoidRootPart.CFrame.RightVector* vector.create(1,0,1),script.Parent.HumanoidRootPart.CFrame.RightVector) 
	local s2 = vector.angle(script.Parent.HumanoidRootPart.CFrame.RightVector* vector.create(1,0,1),(workspace.targetB.Position - script.Parent.HumanoidRootPart.Position)* vector.create(1,0,1)) 

	local vAng = -1*((script.Parent.HumanoidRootPart.Position.Y -  workspace.targetB.Position.Y) / math.abs((script.Parent.HumanoidRootPart.Position.Y -  workspace.targetB.Position.Y))) * vector.angle(workspace.targetB.Position-script.Parent.HumanoidRootPart.Position,(workspace.targetB.Position * vector.create(1,0,1) + vector.create(0,script.Parent.HumanoidRootPart.Position.Y,0))-script.Parent.HumanoidRootPart.Position)

	--print(vertAngle)
	ra.Transform = CFrame.identity
	ha.Transform = CFrame.identity
	ha.C0 = ha.C0:Lerp(haC0 *  CFrame.Angles(0,math.clamp(s2-1.7,-3,2),0) * CFrame.Angles(math.clamp(vAng,-3,2),0,0),0.1)
	ra.C0 = ra.C0:Lerp(raC0 * CFrame.Angles(0,math.clamp(s2-0.1,-3,2),0)*CFrame.Angles(0,0,0)* CFrame.Angles(0,0,math.clamp(vAng+0.75,-3,2)),0.1) 
end)

This is how it works without animation(as it should be):

this is how it works with animation aims slightly off:

this is the animation:
Capture

1 Like

So let’s get the obvious out the way;

when the animation is not playing the head moves properly?
can you send a short recording of what happens when the animation is playing?

1 Like

If you want the head to have no effect, then two ways,

completely remove the track for head in your animation via the editor.
or just set ha.Transform = CFrame.identity , each update to cancel out the animator.

1 Like

@lunarrest i have updated my post. please check it out

1 Like

Still not working. it does the same. my animation simply rotates the upper torso 20 degrees left

1 Like

I really need help on that one

1 Like

Anyone help?? please. how do i do it?

1 Like