+ float bob_limit = cl_bob_limit.value;
+
+ if (cl_bob_limit_heightcheck.integer)
+ {
+ // use traces to determine what range the view can bob in, and scale down the bob as needed
+ float trace1fraction;
+ float trace2fraction;
+ vec3_t bob_height_check_dest;
+
+ // these multipliers are expanded a bit (the actual bob sin range is from -0.4 to 1.0) to reduce nearclip issues, especially on water surfaces
+ bob_height_check_dest[0] = vieworg[0];
+ bob_height_check_dest[1] = vieworg[1];
+ bob_height_check_dest[2] = vieworg[2] + cl_bob_limit.value * 1.1f;
+ trace = CL_TraceLine(vieworg, bob_height_check_dest, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY | (cl_bob_limit_heightcheck_dontcrosswatersurface.integer ? SUPERCONTENTS_LIQUIDSMASK : 0), collision_extendmovelength.value, true, false, NULL, false, true);
+ trace1fraction = trace.fraction;
+
+ bob_height_check_dest[0] = vieworg[0];
+ bob_height_check_dest[1] = vieworg[1];
+ bob_height_check_dest[2] = vieworg[2] + cl_bob_limit.value * -0.5f;
+ trace = CL_TraceLine(vieworg, bob_height_check_dest, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY | (cl_bob_limit_heightcheck_dontcrosswatersurface.integer ? SUPERCONTENTS_LIQUIDSMASK : 0), collision_extendmovelength.value, true, false, NULL, false, true);
+ trace2fraction = trace.fraction;
+
+ bob_limit *= min(trace1fraction, trace2fraction);
+ }
+