How to fix sliding/surfing from slope surface in Quake
Author: kleskbyAs you could notice while playing quake, if you stand on a slope you slowly move down the slope. This is very annoying player physics bug in Quake 1.
Solution 1.
If you are using Darkplaces/FTE you can just enable build-in fix. Set sv_gameplayfix_nogravityonground 1. Also this requires sv_gameplayfix_downtracesupportsongroundflag 1.
sv_gameplayfix_downtracesupportsongroundflag is "1" ["0"] // prevents very short moves from clearing onground (which may make the player stick to the floor at high netfps)
sv_gameplayfix_nogravityonground is "1" ["0"] // turn off gravity when on ground (to get rid of sliding)
Solution 2 (Native quake).
Open client.qc, at the bottom of PlayerPreThink add the following code:
if(self.movetype != MOVETYPE_NOCLIP && clienttype(self) != CLIENTTYPE_BOT) //SLIDING (SURFING) FIX
{
if(self.flags & FL_ONGROUND && vlen(self.velocity) < 30)
{
traceline (self.origin, self.origin - '0 0 42', TRUE, self); //detecting slope angle
if(trace_fraction > 0.65) self.movetype = MOVETYPE_BOUNCE;
else self.movetype = MOVETYPE_WALK;
}
else self.movetype = MOVETYPE_WALK;
}
The function checks if the player is not in noclip mode and is not a bot, then it checks if the player is on the ground (FL_ONGROUND
flag is set) and has a velocity less than 30. If both conditions are met, the code checks the angle of the ground the player is standing on by performing a traceline
from the player's current position to a point just below them. The TRUE
parameter indicates that the trace should stop when it hits a solid surface.
If the trace_fraction
(which is the fraction of the trace line that was traveled before hitting a solid surface) is greater than 0.65, the player's movement type is set to MOVETYPE_BOUNCE
(can be other movetype). Otherwise, returning player movement type to a normal state.
Tags: DarkPlaces, QuakeC, movement