Lock CalcView at an angle?

Hi, so I’ve been searching on the wiki for around 15 minutes now, and i still can’t find anything that helps me. So i decided to post it on here, and hopefully get some help from all the awesome coders on here.

So I’m making this thirdperson thingy, and i want to know how i can lock it at a certain angle, so you only can move your mouse left and right and not up and down.

Here’s my code:

function MyCalcView(ply, pos, angles, fov)
	local view = { }

	view.origin = pos-(angles:Forward()*100)
	view.angles = angles
	view.fov = fov
	return view
hook.Add( "CalcView", "MyCalcView", MyCalcView )
hook.Add( "ShouldDrawLocalPlayer", "MyShouldDrawLocalPlayer", function( ply )
	return true
end )

Thanks a bunch for taking time out of your day to help me.

view.angles.p = whateveryouwant

Thanks a bunch for your help, but even though i set view.angles to an angle, I’m still able to freely move the mouse around. It puts the CalcView at just the angle i want, but I’m still able to move the mouse freely around.

I only want the player to be able to move the mouse left and right.

Check my post out. Someone wanted something similar.

This was EXACTLY what i was looking for. Thank you so much.