FIx rubberbanding

This commit is contained in:
INeedBots 2021-03-11 15:11:19 -06:00
parent b0d1fbfb19
commit 9feb4745d4

View File

@ -133,6 +133,8 @@ resetBotVars()
self.bot.stop_move = false; self.bot.stop_move = false;
self.bot.greedy_path = false; self.bot.greedy_path = false;
self.bot.climbing = false; self.bot.climbing = false;
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self.bot.isfrozen = false; self.bot.isfrozen = false;
self.bot.sprintendtime = -1; self.bot.sprintendtime = -1;
@ -147,6 +149,7 @@ resetBotVars()
self.bot.semi_time = false; self.bot.semi_time = false;
self.bot.jump_time = undefined; self.bot.jump_time = undefined;
self.bot.last_fire_time = -1;
self.bot.is_cur_full_auto = false; self.bot.is_cur_full_auto = false;
self.bot.cur_weap_dist_multi = 1; self.bot.cur_weap_dist_multi = 1;
@ -250,7 +253,7 @@ doBotMovement()
// check if need to jump // check if need to jump
bt = bulletTrace(startPosForward, startPosForward - (0, 0, 40), false, self); bt = bulletTrace(startPosForward, startPosForward - (0, 0, 40), false, self);
if (bt["fraction"] < 1 && bt["normal"][2] > 0.75 && i > 1.5 && !self isOnLadder()) if (bt["fraction"] < 1 && bt["normal"][2] > 0.9 && i > 1.5 && !self isOnLadder())
{ {
i = 0; i = 0;
self thread jump(); self thread jump();
@ -310,7 +313,7 @@ watchHoldBreath()
if(self.bot.isfrozen) if(self.bot.isfrozen)
continue; continue;
self holdbreath(self playerADS() >= 1); self holdbreath(self playerADS() > 0);
} }
} }
@ -1177,7 +1180,7 @@ aim()
//c4 logic here, but doesnt work anyway //c4 logic here, but doesnt work anyway
canADS = (self canAds(dist, curweap) && conedot > 0.65); canADS = (self canAds(dist, curweap) && conedot > 0.75);
if (canADS) if (canADS)
self thread pressADS(); self thread pressADS();
@ -1214,7 +1217,7 @@ aim()
if(!self canFire(curweap) || !self isInRange(dist, curweap)) if(!self canFire(curweap) || !self isInRange(dist, curweap))
continue; continue;
canADS = (self canAds(dist, curweap) && conedot > 0.65); canADS = (self canAds(dist, curweap) && conedot > 0.75);
if (canADS) if (canADS)
self thread pressADS(); self thread pressADS();
@ -1254,6 +1257,8 @@ aim()
*/ */
botFire() botFire()
{ {
self.bot.last_fire_time = getTime();
if(self.bot.is_cur_full_auto) if(self.bot.is_cur_full_auto)
{ {
self thread pressFire(); self thread pressFire();
@ -1368,6 +1373,8 @@ walk()
if(self maps\mp\_flashgrenades::isFlashbanged()) if(self maps\mp\_flashgrenades::isFlashbanged())
{ {
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self botMoveTo(self.origin + self GetVelocity()*500); self botMoveTo(self.origin + self GetVelocity()*500);
continue; continue;
} }
@ -1480,6 +1487,8 @@ strafe(target)
if(traceRight["fraction"] > traceLeft["fraction"]) if(traceRight["fraction"] > traceLeft["fraction"])
strafe = traceRight["position"]; strafe = traceRight["position"];
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self botMoveTo(strafe); self botMoveTo(strafe);
wait 2; wait 2;
self notify("kill_goal"); self notify("kill_goal");
@ -1591,39 +1600,34 @@ doWalk(goal, dist, isScriptGoal)
self thread watchOnGoal(goal, distsq); self thread watchOnGoal(goal, distsq);
current = self initAStar(goal); current = self initAStar(goal);
// if a waypoint is closer than the goal // skip waypoints we already completed to prevent rubber banding
//if (current >= 0 && DistanceSquared(self.origin, level.waypoints[self.bot.astar[current]].origin) < DistanceSquared(self.origin, goal)) if (current > 0 && self.bot.astar[current] == self.bot.last_next_wp && self.bot.astar[current-1] == self.bot.last_second_next_wp)
//{ current = self removeAStar();
if (current >= 0)
{
// check if a waypoint is closer than the goal
wpOrg = level.waypoints[self.bot.astar[current]].origin;
ppt = PlayerPhysicsTrace(self.origin + (0,0,32), wpOrg, false, self);
if (DistanceSquared(self.origin, wpOrg) < DistanceSquared(self.origin, goal) || DistanceSquared(wpOrg, ppt) > 1.0)
{
while(current >= 0) while(current >= 0)
{ {
// skip down the line of waypoints and go to the waypoint we have a direct path too
/*for (;;)
{
if (current <= 0)
break;
ppt = PlayerPhysicsTrace(self.origin + (0,0,32), level.waypoints[self.bot.astar[current-1]].origin, false, self);
if (DistanceSquared(level.waypoints[self.bot.astar[current-1]].origin, ppt) > 1.0)
break;
if (level.waypoints[self.bot.astar[current-1]].type == "climb" || level.waypoints[self.bot.astar[current]].type == "climb")
break;
current = self removeAStar();
}*/
self.bot.next_wp = self.bot.astar[current]; self.bot.next_wp = self.bot.astar[current];
self.bot.second_next_wp = -1; self.bot.second_next_wp = -1;
if(current != 0) if(current > 0)
self.bot.second_next_wp = self.bot.astar[current-1]; self.bot.second_next_wp = self.bot.astar[current-1];
self notify("new_static_waypoint"); self notify("new_static_waypoint");
self movetowards(level.waypoints[self.bot.next_wp].origin); self movetowards(level.waypoints[self.bot.next_wp].origin);
self.bot.last_next_wp = self.bot.next_wp;
self.bot.last_second_next_wp = self.bot.second_next_wp;
current = self removeAStar(); current = self removeAStar();
} }
//} }
}
self.bot.next_wp = -1; self.bot.next_wp = -1;
self.bot.second_next_wp = -1; self.bot.second_next_wp = -1;
@ -1631,6 +1635,8 @@ doWalk(goal, dist, isScriptGoal)
if(DistanceSquared(self.origin, goal) > distsq) if(DistanceSquared(self.origin, goal) > distsq)
{ {
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self movetowards(goal); // any better way?? self movetowards(goal); // any better way??
} }