From 4e6f0bf41cecf10d7038b39f63d1bd3583725a91 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Thu, 17 Aug 2017 04:44:01 +0200 Subject: [PATCH] scale dodging force according to currect velocity yes, this is the reason i am doing this whole thing --- mutators.cfg | 7 +++- .../mutators/mutator/dodging/sv_dodging.qc | 38 +++++++++---------- qcsrc/common/stats.qh | 14 +++++-- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/mutators.cfg b/mutators.cfg index 33076b562..012a2adf1 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -14,8 +14,11 @@ set sv_dodging_air_dodging 0 set sv_dodging_wall_dodging 0 "allow dodging off walls" set sv_dodging_delay 0.5 "determines how long a player has to wait to be able to dodge again after dodging" set sv_dodging_up_speed 200 "the jump velocity of the dodge" -set sv_dodging_horiz_speed 400 "the horizontal velocity of the dodge" -set sv_dodging_horiz_speed_frozen 200 "the horizontal velocity of the dodge while frozen" +set sv_dodging_horiz_speed_min 200 "the lower bound of current velocity for force scaling" +set sv_dodging_horiz_speed_max 1000 "the upper bound of current velocity for force scaling" +set sv_dodging_horiz_force_slowest 400 "the horizontal velocity of the dodge when current velocity is <= sv_dodging_horiz_speed_min, values between min and max are linearly scaled" +set sv_dodging_horiz_force_fastest 400 "the horizontal velocity of the dodge when current velocity is >= sv_dodging_horiz_speed_max, values between min and max are linearly scaled" +set sv_dodging_horiz_force_frozen 200 "the horizontal velocity of the dodge while frozen" set sv_dodging_ramp_time 0.1 "a ramp so that the horizontal part of the dodge is added smoothly (seconds)" set sv_dodging_height_threshold 10 "the maximum height above ground where to allow dodging" set sv_dodging_wall_distance_threshold 10 "the maximum distance from a wall that still allows dodging" diff --git a/qcsrc/common/mutators/mutator/dodging/sv_dodging.qc b/qcsrc/common/mutators/mutator/dodging/sv_dodging.qc index 3eed2de1b..b3a938bcb 100644 --- a/qcsrc/common/mutators/mutator/dodging/sv_dodging.qc +++ b/qcsrc/common/mutators/mutator/dodging/sv_dodging.qc @@ -7,8 +7,11 @@ #define PHYS_DODGING_DISTANCE_THRESHOLD autocvar_sv_dodging_wall_distance_threshold #define PHYS_DODGING_FROZEN_DOUBLETAP autocvar_sv_dodging_frozen_doubletap #define PHYS_DODGING_HEIGHT_THRESHOLD autocvar_sv_dodging_height_threshold -#define PHYS_DODGING_HORIZ_SPEED autocvar_sv_dodging_horiz_speed -#define PHYS_DODGING_HORIZ_SPEED_FROZEN autocvar_sv_dodging_horiz_speed_frozen +#define PHYS_DODGING_HORIZ_SPEED_MIN autocvar_sv_dodging_horiz_speed_min +#define PHYS_DODGING_HORIZ_SPEED_MAX autocvar_sv_dodging_horiz_speed_max +#define PHYS_DODGING_HORIZ_FORCE_SLOWEST autocvar_sv_dodging_horiz_force_slowest +#define PHYS_DODGING_HORIZ_FORCE_FASTEST autocvar_sv_dodging_horiz_force_fastest +#define PHYS_DODGING_HORIZ_FORCE_FROZEN autocvar_sv_dodging_horiz_force_frozen #define PHYS_DODGING_RAMP_TIME autocvar_sv_dodging_ramp_time #define PHYS_DODGING_UP_SPEED autocvar_sv_dodging_up_speed #define PHYS_DODGING_WALL autocvar_sv_dodging_wall_dodging @@ -22,8 +25,11 @@ #define PHYS_DODGING_DISTANCE_THRESHOLD STAT(DODGING_DISTANCE_THRESHOLD, this) #define PHYS_DODGING_FROZEN_DOUBLETAP STAT(DODGING_FROZEN_DOUBLETAP, this) #define PHYS_DODGING_HEIGHT_THRESHOLD STAT(DODGING_HEIGHT_THRESHOLD, this) -#define PHYS_DODGING_HORIZ_SPEED STAT(DODGING_HORIZ_SPEED, this) -#define PHYS_DODGING_HORIZ_SPEED_FROZEN STAT(DODGING_HORIZ_SPEED_FROZEN, this) +#define PHYS_DODGING_HORIZ_SPEED_MIN STAT(DODGING_HORIZ_SPEED_MIN, this) +#define PHYS_DODGING_HORIZ_SPEED_MAX STAT(DODGING_HORIZ_SPEED_MAX, this) +#define PHYS_DODGING_HORIZ_FORCE_SLOWEST STAT(DODGING_HORIZ_FORCE_SLOWEST, this) +#define PHYS_DODGING_HORIZ_FORCE_FASTEST STAT(DODGING_HORIZ_FORCE_FASTEST, this) +#define PHYS_DODGING_HORIZ_FORCE_FROZEN STAT(DODGING_HORIZ_FORCE_FROZEN, this) #define PHYS_DODGING_RAMP_TIME STAT(DODGING_RAMP_TIME, this) #define PHYS_DODGING_UP_SPEED STAT(DODGING_UP_SPEED, this) #define PHYS_DODGING_WALL STAT(DODGING_WALL, this) @@ -125,20 +131,13 @@ bool is_close_to_ground(entity this, float threshold) #undef X -// TODO use real cvars -/*float autocvar_velocity_min = 200; -float autocvar_velocity_max = 700; -float autocvar_force_min = 50; -float autocvar_force_max = 350;*/ -float determine_speed(entity player) { - float x = PHYS_FROZEN(player) ? PHYS_DODGING_HORIZ_SPEED_FROZEN : PHYS_DODGING_HORIZ_SPEED; - x = x; // unused - return x; - - /*float horiz_vel = vlen(vec2(player.velocity)); - // force min and max are inverted - the faster you are the wekaer dodging becomes - // TODO document cvars in cfg - return map_bound_ranges(horiz_vel, autocvar_velocity_min, autocvar_velocity_max, autocvar_force_max, autocvar_force_min);*/ +float determine_force(entity player) { + if (PHYS_FROZEN(player)) return PHYS_DODGING_HORIZ_FORCE_FROZEN; + + float horiz_vel = vlen(vec2(player.velocity)); + return map_bound_ranges(horiz_vel, + PHYS_DODGING_HORIZ_SPEED_MIN, PHYS_DODGING_HORIZ_SPEED_MAX, + PHYS_DODGING_HORIZ_FORCE_SLOWEST, PHYS_DODGING_HORIZ_FORCE_FASTEST); } bool PM_dodging_checkpressedkeys(entity this) @@ -194,8 +193,7 @@ bool PM_dodging_checkpressedkeys(entity this) this.dodging_action = 1; this.dodging_single_action = 1; - //this.dodging_velocity_gain = PHYS_DODGING_HORIZ_SPEED; - this.dodging_force_total = determine_speed(this); + this.dodging_force_total = determine_force(this); this.dodging_force_remaining = this.dodging_force_total; this.dodging_direction.x = tap_direction_x; diff --git a/qcsrc/common/stats.qh b/qcsrc/common/stats.qh index ac058edb0..ee13d9d47 100644 --- a/qcsrc/common/stats.qh +++ b/qcsrc/common/stats.qh @@ -217,8 +217,11 @@ float autocvar_sv_dodging_wall_distance_threshold; bool autocvar_sv_dodging_frozen; bool autocvar_sv_dodging_frozen_doubletap; float autocvar_sv_dodging_height_threshold; -float autocvar_sv_dodging_horiz_speed; -float autocvar_sv_dodging_horiz_speed_frozen; +float autocvar_sv_dodging_horiz_speed_min; +float autocvar_sv_dodging_horiz_speed_max; +float autocvar_sv_dodging_horiz_force_slowest; +float autocvar_sv_dodging_horiz_force_fastest; +float autocvar_sv_dodging_horiz_force_frozen; float autocvar_sv_dodging_ramp_time; float autocvar_sv_dodging_up_speed; bool autocvar_sv_dodging_wall_dodging; @@ -232,8 +235,11 @@ REGISTER_STAT(DODGING_DELAY, float, autocvar_sv_dodging_delay) REGISTER_STAT(DODGING_DISTANCE_THRESHOLD, float, autocvar_sv_dodging_wall_distance_threshold) REGISTER_STAT(DODGING_FROZEN_DOUBLETAP, int, autocvar_sv_dodging_frozen_doubletap) REGISTER_STAT(DODGING_HEIGHT_THRESHOLD, float, autocvar_sv_dodging_height_threshold) -REGISTER_STAT(DODGING_HORIZ_SPEED, float, autocvar_sv_dodging_horiz_speed) -REGISTER_STAT(DODGING_HORIZ_SPEED_FROZEN, float, autocvar_sv_dodging_horiz_speed_frozen) +REGISTER_STAT(DODGING_HORIZ_SPEED_MIN, float, autocvar_sv_dodging_horiz_speed_min) +REGISTER_STAT(DODGING_HORIZ_SPEED_MAX, float, autocvar_sv_dodging_horiz_speed_max) +REGISTER_STAT(DODGING_HORIZ_FORCE_SLOWEST, float, autocvar_sv_dodging_horiz_force_slowest) +REGISTER_STAT(DODGING_HORIZ_FORCE_FASTEST, float, autocvar_sv_dodging_horiz_force_fastest) +REGISTER_STAT(DODGING_HORIZ_FORCE_FROZEN, float, autocvar_sv_dodging_horiz_force_frozen) REGISTER_STAT(DODGING_RAMP_TIME, float, autocvar_sv_dodging_ramp_time) REGISTER_STAT(DODGING_UP_SPEED, float, autocvar_sv_dodging_up_speed) REGISTER_STAT(DODGING_WALL, bool, autocvar_sv_dodging_wall_dodging) -- 2.39.2