Encountering angle problem with CalcView

I seem to be having a problem where by I used calcview to make a ‘smoothly transitioning aim’, that is, my aim smoothly follows where i’m looking instead of always being at a constant sensitivity… not quite the easiest thing to explain.
Anyway, the problem i’m having is that when I get to a certain degree on yaw, i will instantly snap around 360 degrees in the other direction to be facing where i was just a second ago but slightly offset. If i then move my cursor back in the other direction to that slight angle it does the same thing in the opposite way.
In simple terms, the way im calculating the angle is:
CurrentAngle = CurrentAngle + ( (Where I want to look - CurrentAngle) * 0.1 )
and the code is



local ChangeAngle
function CreateActualView( ply, vec, ang, fov )
	local view = {}	 
	view.origin = vec
	ChangeAngle = ChangeAngle + ( ( LocalPlayer():EyeAngles()  - ChangeAngle) * 0.1 )
	view.angles = ChangeAngle
	view.fov = ViewFov
	return view
end	
hook.Add( "CalcView", "ViewCalculations", CreateActualView )


I’ve tried using RotateAroundAxis to no avail
Please help.
Oh also, i’m fairly sure this is primarily a mathematical problem to do with the way angle axes work, but i don’t know how to get around it :S

Sounds like the gimbal lock, one solution are quaternions afaik, eg. adding a forth axis to the angle, that’s kinda complex though.

As a work around you probably can transform the angle to a vector, perform the interpolation.

That way you’d loose the roll though, thus you need to store it temporary.

Aha shit i didn’t think it’d be that simple!
I just changed it to



local ChangeAngle = Vector(0,0,0)
function CreateActualView( ply, vec, ang, fov )
	local view = {}
	view.origin = vec
	ChangeAngle = ChangeAngle + ((( LocalPlayer():EyeAngles()):Forward()) - ChangeAngle) * 0.1 
	view.angles = ChangeAngle:Angle()
	view.fov = ViewFov
	return view
end	
hook.Add( "CalcView", "ViewCalculations", CreateActualView )


Thanks so much :)!