- if(this.aistatus & AI_STATUS_RUNNING)
- if(this.goalcurrent.classname=="waypoint")
- if(vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed)) // if -really- running
- {
- if(vdist(this.origin - this.goalcurrent.origin, <, 150))
+ // check goalstack01 to make sure waypoint isn't the final goal
+ if((this.aistatus & AI_STATUS_RUNNING) && this.goalcurrent.classname == "waypoint" && !(this.goalcurrent.wpflags & WAYPOINTFLAG_JUMP)
+ && this.goalstack01 && !wasfreed(this.goalstack01) && vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed))
+ {
+ vector gco = this.goalcurrent.origin;
+ float min_dist = BOT_BUNNYHOP_WP_DETECTION_RANGE;
+ // also detect waypoints when bot is way above them but with a narrower horizontal range
+ // so to increase chances bot ends up in the standard range (optimizes nearest waypoint finding)
+ if(vdist(this.origin - gco, <, min_dist)
+ || (vdist(vec2(this.origin - gco), <, min_dist * 0.5) && vdist(this.origin - eZ * 1.5 * min_dist - gco, <, min_dist)))