Viewmodel Flying away

I am using a viewmodel system I have been using for the last 6 months with minor issues. For some reason with this new viewmodel. It likes to fly up. The interesting part is that in the output when printing both the camera & VM positions, they are said to both be in the same location, however visually, the viewmodel continues to fly upwards. Any fixes?

local ViewModel
local camera = workspace.Camera
local swayCF = CFrame.new()

tool.Equipped:Connect(function()
	equipped = true
	ViewModel = game:GetService("ReplicatedStorage").Viewmodels.Overlord:Clone()
	ViewModel.Parent = camera

	preloadAnims()
	equipAnim()
	idleAnim()
end)

tool.Unequipped:Connect(function()
	equipped = false
	ViewModel:Destroy()
end)

RS.RenderStepped:Connect(function()
	if player.Character then
		if player.Character:WaitForChild("Humanoid").Health <= 0 or player.Character == nil then

			if camera:FindFirstChild("Overlord") ~= nil then
				workspace.Camera.Overlord:Destroy()
			end
		end

		if equipped == true then

			if camera:FindFirstChild("Overlord") ~= nil then
				camera.Overlord:PivotTo(camera.CFrame)
				for i, v in pairs(camera.Overlord:GetChildren()) do
					if v:IsA("BasePart") then
						v.CanCollide = false
						v.CanQuery = false
						v.CanTouch = false
					end
				end

				local mouseDelta = UIS:GetMouseDelta()/50

				local swayX = math.clamp(mouseDelta.X, -0.05,0.05)
				local swayY = math.clamp(mouseDelta.Y, -0.05,0.05)

				swayCF = swayCF:Lerp(CFrame.new(swayX, swayY, 0), .3)

				camera.Overlord:PivotTo(camera.CFrame * swayCF)
				print("camera: ",camera.CFrame.Position)
				print("VM: ",camera.Overlord.PrimaryPart.CFrame.Position)
			end
		end
	end
end)

You’re using :PivotTo() which moves your whole model, try printing out camera.overlord:GetPivot() and see if any values change from what’s expected.

Another thing – does the viewmodel fly upwards continuously even when you’re not moving anything (your mouse & your character)?

Doesn’t :PivotTo() move the primary part if available? The primary part in this model is the CameraBone. Anyways, here is a recording. The camera is printing its position & the viewmodel is printing :GetPivot()

1 Like

PivotTo() modifies the model’s WorldPivot. On default, it would be set to the center of the model – however, the pivot is set to the PrimaryPart if it ever exists.


Anyways, I want you to try these lines seperately and see what behavior each of them do:

camera.Overlord:PivotTo(camera.CFrame) -- 1
camera.Overlord:PivotTo(camera.CFrame * CFrame.new(0, 1, 0)) -- 2

…aswell as add another print:

print("VM2: ",camera.Overlord:GetPivot().Position)

camera.CFrame →


camera.CFrame * CFrame.new(0,1,0) →

Somehow the Motor6d connection between the HumanoidRootPart & CameraBone was severed during animation. I just had to create a new Motor6d weld.