.float last_BACKWARD_KEY_time;
.float last_LEFT_KEY_time;
.float last_RIGHT_KEY_time;
+.float last_JUMP_KEY_time;
// these store the movement direction at the time of the dodge action happening.
.float dodging_direction_x;
self.last_BACKWARD_KEY_time = 0;
self.last_RIGHT_KEY_time = 0;
self.last_LEFT_KEY_time = 0;
+ self.last_JUMP_KEY_time = 0;
self.last_dodging_time = 0;
self.dodging_action = 0;
self.dodging_single_action = 0;
float common_factor;
- // is dodging enabled at all? if not, do nothing..
+ float clean_up_and_do_nothing;
+
+ clean_up_and_do_nothing = 0;
+
if (g_dodging == 0)
+ clean_up_and_do_nothing = 1;
+
+ // when swimming, no dodging allowed..
+ if (self.waterlevel >= WATERLEVEL_SWIMMING)
+ clean_up_and_do_nothing = 1;
+
+ if (clean_up_and_do_nothing != 0) {
+ self.dodging_action = 0;
+ self.dodging_direction_x = 0;
+ self.dodging_direction_y = 0;
return 0;
+ }
// make sure v_up, v_right and v_forward are sane
makevectors(self.angles);
return 0;
}
+float check_close_to_ground(float threshold) {
+ vector trace_start;
+ vector trace_end;
+
+ // determine height above ground is below a threshold
+ trace_start = self.origin;
+ trace_end = self.origin - (1000*v_up);
+
+ tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);
+
+ // check if the trace hit anything at all
+ if (trace_fraction > 1)
+ return 0;
+
+ if(self.origin_z - trace_endpos_z < threshold)
+ return 1;
+
+ return 0;
+}
+
+
MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) {
// print("dodging_PlayerPhysics\n");
float length;
float dodge_detected;
- vector trace_start;
- vector trace_end;
- float height_above_ground;
-
if (g_dodging == 0)
return 0;
if ((time - self.last_dodging_time) < cvar("sv_dodging_delay"))
return 0;
- // determine height above ground is below a threshold
- trace_start = self.origin;
- trace_end = self.origin - (1000*v_up);
-
- tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);
-
- // check if the trace hit anything at all
- if (trace_fraction > 1)
+ if (check_close_to_ground(cvar("sv_dodging_height_threshold")) != 1
+ && check_close_to_wall(cvar("sv_dodging_wall_distance_threshold")) != 1)
return 0;
- height_above_ground = self.origin_z - trace_endpos_z;
-
- // check if our feet are on the ground or at least close :D
- if ((height_above_ground > (fabs(PL_MIN_z) + cvar("sv_dodging_height_threshold")))
- && (check_close_to_wall(cvar("sv_dodging_wall_distance_threshold")) != 1))
- return 0;
+ // remember last jump key time, so we can check in dodging code, if it
+ // was pressed between the two dodges..
+ if (self.BUTTON_JUMP)
+ self.last_JUMP_KEY_time = time;
if (self.movement_x > 0) {
// is this a state change?
if (dodge_detected == 1) {
- if (self.movement_z > 0)
- self.movement_z = 0;
+ // If the player pressed JUMP between the two taps, disallow dodging,
+ // cause he obviously wants to jump instead
+ if ((time - self.last_JUMP_KEY_time) < self.cvar_cl_dodging_timeout)
+ return 0;
self.last_dodging_time = time;