- VectorMA(stuckorigin, -stucktrace.startdepth, stucktrace.startdepthnormal, stuckorigin);
+ VectorMA(testorigin, -stucktrace.startdepth, stucktrace.startdepthnormal, targetorigin);
+ // Trace to targetorigin so we don't set it out of the world in complex cases.
+ if (prog == SVVM_prog)
+ stucktrace = SV_TraceBox(testorigin, stuckmins, stuckmaxs, targetorigin, pass ? MOVE_WORLDONLY : MOVE_NOMONSTERS, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value);
+ else
+ stucktrace = CL_TraceBox(testorigin, stuckmins, stuckmaxs, targetorigin, pass ? MOVE_WORLDONLY : MOVE_NOMONSTERS, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value, pass ? false : true, false, NULL, false);
+ if (stucktrace.fraction)
+ VectorCopy(stucktrace.endpos, testorigin);
+ else
+ break; // Can't move it so no point doing more iterations on this pass.