So I’m trying to find a way to make my viewmodel’s movement more smooth, and not just instant snap to the camera. I’d like to use lerp to do this, but I have a problem, the viewmodel delays behind the camera.
Other people have had the problem, and posted about it, but I can’t find a straight answer that I can understand.
My code (in a RenderStepped function):
if loadout.current.PrimaryPart ~= nil then
loadout.current.HumanoidRootPart.CFrame = loadout.current.HumanoidRootPart.CFrame:lerp(thing,0.2)
end
Loadout.current is the gun
“thing” is the camera CFrame multiplied by walking offsets, recoil offsets, etc. (these aren’t the issues)
Video:
I’ve dug into this developer hub article, but to no avail. I think what I might be looking for is ignoring the XYZ values and using the camera’s, but not the orientation values.
Now I just see the viewmodel at the middle of the map.
Also I forgot to give context on what “thing” is, it’s basically just the camera CFrame multiplied by recoil offsets, walking offsets, aiming offsets, etc, and Loadout.current is the viewmodel
Is that not what you wanted? You used Lerp, and now it’s moving slower, and not instantly snapping. I guess you could try increasing the alpha value from 0.2 to 0.5 or higher.
I’ve just realized something- directly setting the position and orientation of the root part doesn’t apply to the welds/motor6ds.
This is my code currently:
local function CFrameToOrientation(cf)
local x, y, z = cf:ToOrientation()
return Vector3.new(math.deg(x), math.deg(y), math.deg(z))
end
local lthing = loadout.current.HumanoidRootPart.Orientation:lerp(CFrameToOrientation(thing),0.2)
loadout.current.HumanoidRootPart.Position = workspace.CurrentCamera.CFrame.Position
loadout.current.HumanoidRootPart.Orientation = lthing
If the humanoidrootpart is selected in game, you can see it locked onto the camera with the correct orientation and such, but the arms are not following. I think if I were to combine the orientation and position and make it into a CFrame somehow, and use :SetPrimaryPartCFrame(), this will work?
local function CFrameToOrientation(cf)
local x, y, z = cf:ToOrientation()
return Vector3.new(math.deg(x),math.deg(y),math.deg(z))
end
local lthing = loadout.current.HumanoidRootPart.Orientation:lerp(CFrameToOrientation(thing),0.2)
loadout.current.HumanoidRootPart:SetPrimaryPartCFrame(CFrame.new(workspace.CurrentCamera.CFrame.Position)*CFrame.Angles(math.rad(lthing.X),math.rad(lthing.Y),math.rad(lthing.Z)))