# Smoothen value?

Hello,
I’m trying to make a smooth mouse sway via CreateMove and CalcView. The only issue is that I need to smoothen out mX, because it feels choppy when you’ve got 20 fps.
[lua]
local mX = 0;
local mY = 0;

hook.Add( “CreateMove”, “Camera:GetValues”, function( _cmd )
mX = _cmd:GetMouseX()/64;
end );

function SmoothCam(ply, pos, ang, fov)
local view = {};
ang:RotateAroundAxis(ang:Forward(), mX);
view.origin = pos;
view.angles = ang;
view.fov = 90;
return view
end

[/lua]

How can I do this?

[lua]
mX = Lerp(mX,_cmd:GetMouseX()/64,0.1);
[/lua]

Going to write this on my phone so apologies for inaccuracies but you need to multiply by delta time. You can calculate delta time by taking the difference between the CurTime() and the last CurTime() of the same hook. Using this value you can get a value that makes such things like input independent of frame rate so to say. Pseudoish application:

[lua]
local mX = 0
local mY = 0
local lastCalcView = 0

hook.Add( “CreateMove”, “Camera:GetValues”, function( _cmd )
mX = _cmd:GetMouseX()/64; – you’ll probably want to divide by less and multiply more since delta time is low! (0.01…)
end );

local function SmoothCam(ply, pos, ang, fov)
local deltatime = CurTime() - lastCalcView
lastCalcView = CurTime()

``````local view = {};
ang:RotateAroundAxis(ang:Forward(), mX * deltaTime);
view.origin = pos;
view.angles = ang;
view.fov = 90;
return view
``````

end