I have a local script where I update the viewmodel cframe to the player’s camera cframe and it’s been working great, however I’ve tried to add inertia using Lerp but it jitters way too much.
WITHOUT LERP:
LOCAL SCRIPT:
local targetCFrame = camera.CFrame
local currentCFrame = inventoryData.viewmodel.PrimaryPart.CFrame
local newCFrame = inertia.ApplyInertia(currentCFrame, targetCFrame, deltaTime)
inventoryData.viewmodel:SetPrimaryPartCFrame(newCFrame)
INERTIA MODULE:
local module = {}
module.inertiaSpeed = 30
function module.ApplyInertia(currentCFrame : CFrame, targetCFrame : CFrame, deltaTime : number)
local alpha = module.inertiaSpeed * deltaTime
alpha = math.clamp(alpha, 0, 1)
local lerpedPosition = currentCFrame.Position:Lerp(targetCFrame.Position, alpha)
local finalCF = CFrame.new(lerpedPosition) * targetCFrame.Rotation
return finalCF
end
return module
I’ve tried to fix it using AI and searching the forums, thanks in advance.