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

hook.Add(“CalcView”, “SmoothCam”, SmoothCam);
[/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

hook.Add(“CalcView”, “SmoothCam”, SmoothCam);[/lua]

(oh and stop with the semi colons everywhere, its gross)

You can also get delta time by calling FrameTime()

Ah forgot about that. That may be the better option.

This worked, thank you.
Anyone here by a chance know how to get a player’s velocity?

Awesome, I didn’t know there was a pre-made function for it. Last qustion:
In this video at the end @ ~13 seconds after he finishes rolling, you can see that his camera movement is very smooth. That’s what i’m trying to achieve. How can I do that??