Rotating upper torso and head with camera causes arms to bug out

Here is a video example of what my animation looks like without the code running:
https://gyazo.com/6b0597d2e4c20ab63cd0ed5875d4d164

Here is a video example with the code running. As you can see the arms are pointed out for some odd reason. How could I fix this?
https://gyazo.com/fb82e360ba00323582d21655a17b2d4a

Also for some odd reason it does not do this during the idle animation only walking and running.
This is the code:

local runService = game:GetService('RunService')
local tweenService = game:GetService('TweenService')

local neck = script.Parent:WaitForChild('Head').Neck
local humanoidRootPart = script.Parent:WaitForChild('HumanoidRootPart')
local upperTorso = script.Parent:WaitForChild('UpperTorso')
local waist = upperTorso:WaitForChild('Waist') 

local initWaist = waist.C1
local initNeck = neck.C1

local function getCameraIsOutOfBounds(y)
	y = math.deg(y)
	if math.clamp(y, -90, 90) ~= y then
		return true
	end
end

runService.RenderStepped:Connect(function()
	local cameraRelativeToHRP = humanoidRootPart.CFrame:ToObjectSpace(workspace.CurrentCamera.CFrame):Inverse()
	local x,y,z = cameraRelativeToHRP:ToOrientation()
	if not getCameraIsOutOfBounds(y) then
		local goalNeckC1 = initNeck * CFrame.fromOrientation(cameraRelativeToHRP:ToOrientation())
		local halfPoint = goalNeckC1:Lerp(initNeck, 0.75)
		local neckPoint = goalNeckC1:Lerp(initNeck, 0.4)
		tweenService:Create(waist, TweenInfo.new(0.5), {C1 = CFrame.new(waist.C1.Position) * CFrame.fromOrientation(halfPoint:ToOrientation())}):Play()
		tweenService:Create(neck, TweenInfo.new(0.5), {C1 = CFrame.new(neck.C1.Position) * CFrame.fromOrientation(neckPoint:ToOrientation())}):Play()
	else
		tweenService:Create(waist, TweenInfo.new(0.5), {C1 = initWaist}):Play()
		tweenService:Create(neck, TweenInfo.new(0.5), {C1 = initNeck}):Play()
	end
end) 

This was probably obvious but I removed the waist tween and the problem did not occur meaning it has something to do with the waist tween.

upon further research this solved my issue:

1 Like

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