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)