Making an FPS viewmodel system here
My code binds a function to render step
It creates a realistic bobbing effect by taking the number from tick() and putting it in a sine and cosine wave while moving.
The problem is, while not moving, I’d like the viewmodel to smoothly go back to its default position.
But instead it just seems to do nothing when I try to lerp it.
I’m using the Humanoid.MoveDirection.Magnitude to determine if the player is moving or not.
Is the alpha too small? Am I missing something? Should I come at this differently?
Any help and ideas appreciated
Code below
(for clarity, the Viewmodel variable is simply a model that is parented to workspace by a local script)
local BobOffset = CFrame.new()
local function CalibrateViewModel(Delta)
--Bobbing
if Humanoid.MoveDirection.Magnitude > 0 then
BobOffset = CFrame.new(math.cos(tick() * 5) * 0.2, math.sin(tick() * 10) * 0.14, -Humanoid.CameraOffset.Z/3)
else
--BobOffset = CFrame.new(0, -Humanoid.CameraOffset.Y/3, 0)
BobOffset:Lerp(CFrame.new(0, -Humanoid.CameraOffset.Y/3, 0), 0.7)
end
Viewmodel:PivotTo(
Camera.CFrame * BobOffset
)
end
-- Start
RunService:BindToRenderStep("Test_ViewModelCalibrate", 301, CalibrateViewModel)
I’ll post a video example soon