I’m making an ADS system for a viewmodel, and I need the viewmodel to smoothly lerp to the viewmodel’s ADS part. Here’s the code so far, in RenderStepped:
viewmodel.HumanoidRootPart.CFrame = cam.CFrame * viewmodel.HumanoidRootPart.CFrame:Lerp(viewmodel.ADS.CFrame:ToObjectSpace(viewmodel.HumanoidRootPart.CFrame),0.5*deltaTime)
If I use the code WITHOUT the :Lerp(), it works perfectly, code below.
viewmodel.HumanoidRootPart.CFrame = cam.CFrame * viewmodel.ADS.CFrame:ToObjectSpace(viewmodel.HumanoidRootPart.CFrame)
But for some reason, when I use the code with the Lerp, the viewmodel just instantly disappears. Looking at the CFrame of the viewmodel when aiming shows that it teleports somewhere really far away. Anyone have an idea of what the problem is?
Correct me if I’m wrong, but doesn’t :Lerp() require a time factor? Currently, you are passing the viewmodel and keeping the variable outside of the code.
The changed code might look something like this
local startCFrame = viewmodel.HumanoidRootPart.CFrame
local endCFrame = viewmodel.ADS.CFrame:ToObjectSpace(viewmodel.HumanoidRootPart.CFrame)
viewmodel.HumanoidRootPart.CFrame = cam.CFrame * startCFrame:Lerp(endCFrame, 0.5 * deltaTime)
The :Lerp()'s time (0.5) is correctly syntaxed in the function. I tried the code that you gave, which produced the same result(I think the code is exactly the same as my current one, with 2 extra vars). One thing I did notice on further inspection is that the viewmodel seems to teleport wildly to positions around the world’s center.
Video of glitch attached: Seizure warning