Answering specifically how to clamp a 3D "direction" vector to be within a certain angle of some other direction called "forwards":
direction = Vector3.RotateTowards( forwards, direction, maxRadians, 0 );
If "direction" is already within the given angle of "forwards" then it won't be changed, but if it is at a greater angle then it will be clamped onto the cone of vectors offset by that angle from "forwards".
For the rest, I get very nervous when I see people forcing rigid bodies to specific positions and orientations. Your first port of call with rigid bodies should be forces and torques. Your second port of call is velocities (linear and angular), though it's usually still clearer to express velocity changes as impulses. The third port of call is constraints. Directly modifying position or orientation on a frame-by-frame basis should be a last resort.
↧