Code: Select all
void() aligntoground =
{
traceline (self.origin, self.origin - '0 0 128', TRUE, self);
if(trace_fraction != 1)
{
vector ang = self.angles;
ang_x *= -1;
makevectors(ang);
vector coplanar = v_forward-(v_forward*trace_plane_normal)*trace_plane_normal;
self.angles = vectoangles(coplanar, trace_plane_normal);
}
};
just a quick hack, untested.
traces down to find the ground plane.
figures out the entity's current forward vector (as currently displayed, player or monster).
clips that forward vector to follow the ground.
converts that vector back to an angle, using the ground plane to determin the roll angle.
requires DP_QC_VECTOANGLES_WITH_ROLL.
unlike the previous version, it should orient correctly when facing along a slope (instead of only up/down the slope or whatever that maths was meant to do).