Smooth the transition between 2 angles

Hello , I can’t figure out how to smooth the transition between 2 angles in a Swep. SnapEyeAngles just makes player view instantly go up but I want to smooth that transition , could anybody help me with that ? Thanks.

Use a loop to change the angles based on a timer. So change the angles by 1 every .1-1 second.

LerpAngle. Call that each CreateMove call.

uhm , can you post an example of using LerpAngle? thanks

[lua]local angle2 = Angle(90,90,90)
local curang = Angle(0,0,0)

hook.Add(“CreateMove” , “Wat” , function(ucmd) curang = LerpAngle(0.1 , curang , angle2) ucmd:SetViewAngle(curang) end )[/lua]

Something like that.

[editline]29th January 2011[/editline]

You could also use math.Approach

FlapJack’s version will decellerate over time, use this.
local curAng = LerpAngle(math.min((starttime-CurTime())/duration,1),ang1,ang2)

Where do it put this line of code? Should I hook it?

Same principle as my code, just ralle’s will remain at a constant speed.

Sorry for being stupid , but :
[lua]local function SmoothAngles(ucmd)

local owner = LocalPlayer()
local weapon = owner:GetActiveWeapon()
if weapon.SmoothAngles then
local curAng = LerpAngle(math.min((weapon:GetNWFloat(“starttime”)-CurTime())/0.1,1),owner:EyeAngles(),owner:EyeAngles()-Angle(1,0,0))
hook.Add( “CreateMove” , “SmoothAngles” , SmoothAngles )[/lua]

When i take one of my weapons, my view spins up when i even don’t shoot, assuming that “starttime” float is : [lua]self.Weapon:SetNetworkedFloat( “starttime”, CurTime() )[/lua], it is set everytime that PrimaryAttack() function is called.

Starttime should be set when you start changing the angle.