Use K_MomentumToFacing to give bots a bit better traction

This commit is contained in:
Sally Cochenour 2020-03-28 14:57:49 -04:00
parent ff621d3e46
commit 15bda7da2d
3 changed files with 12 additions and 42 deletions

View file

@ -80,7 +80,7 @@ boolean K_PlayerUsesBotMovement(player_t *player)
return false;
}
fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy)
static fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy)
{
fixed_t v1toc[2] = {cx - v1x, cy - v1y};
fixed_t v1tov2[2] = {v2x - v1x, v2y - v1y};
@ -121,30 +121,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
INT16 anglediff;
wpangle = R_PointToAngle2(player->mo->x, player->mo->y, player->nextwaypoint->mobj->x, player->nextwaypoint->mobj->y);
if (player->mo->momx || player->mo->momy)
{
angle_t movevswp;
moveangle = R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy);
movevswp = (moveangle - wpangle);
if (movevswp > ANGLE_180)
{
movevswp = InvAngle(movevswp);
}
if (movevswp > ANGLE_45)
{
// Use facing direction when going the wrong way
moveangle = player->mo->angle;
}
}
else
{
// Default to facing direction
moveangle = player->mo->angle;
}
moveangle = player->mo->angle;
angle = (moveangle - wpangle);
@ -184,9 +161,9 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
// Full speed ahead!
cmd->forwardmove = 50;
if (dirdist <= 3*rad/4)
if (dirdist <= rad)
{
if (dirdist < rad/4)
if (dirdist < rad/2)
{
// Don't need to turn!
turnamt = 0;
@ -197,12 +174,12 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
turnamt /= 4;
}
}
else
/*else
{
// Actually, don't go too fast...
cmd->forwardmove /= 2;
cmd->buttons |= BT_BRAKE;
}
}*/
}
if (turnamt != 0)

View file

@ -12,5 +12,4 @@
void K_AddBots(UINT8 numbots);
boolean K_PlayerUsesBotMovement(player_t *player);
fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy);
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);

View file

@ -4075,9 +4075,8 @@ static void P_3dMovement(player_t *player)
player->aiming = cmd->aiming<<FRACBITS;
// Forward movement
if (!((player->exiting || mapreset) || (P_PlayerInPain(player) && !onground)))
if (!(P_PlayerInPain(player) && !onground))
{
//movepushforward = cmd->forwardmove * (thrustfactor * acceleration);
movepushforward = K_3dKartMovement(player, onground, cmd->forwardmove);
if (player->mo->movefactor != FRACUNIT) // Friction-scaled acceleration...
@ -4095,12 +4094,8 @@ static void P_3dMovement(player_t *player)
movepushforward = 0;
}
#ifdef ESLOPE
totalthrust.x += P_ReturnThrustX(player->mo, movepushangle, movepushforward);
totalthrust.y += P_ReturnThrustY(player->mo, movepushangle, movepushforward);
#else
P_Thrust(player->mo, movepushangle, movepushforward);
#endif
}
else if (!(player->kartstuff[k_spinouttimer]))
{
@ -4115,15 +4110,10 @@ static void P_3dMovement(player_t *player)
else
movepushside = (cmd->sidemove * FRACUNIT/128) - FixedDiv(player->speed, K_GetKartSpeed(player, true));
#ifdef ESLOPE
totalthrust.x += P_ReturnThrustX(player->mo, movepushsideangle, movepushside);
totalthrust.y += P_ReturnThrustY(player->mo, movepushsideangle, movepushside);
#else
P_Thrust(player->mo, movepushsideangle, movepushside);
#endif
}
#ifdef ESLOPE
if ((totalthrust.x || totalthrust.y)
&& player->mo->standingslope && (!(player->mo->standingslope->flags & SL_NOPHYSICS)) && abs(player->mo->standingslope->zdelta) > FRACUNIT/2) {
// Factor thrust to slope, but only for the part pushing up it!
@ -4141,6 +4131,11 @@ static void P_3dMovement(player_t *player)
}
}
if (K_PlayerUsesBotMovement(player))
{
K_MomentumToFacing(player);
}
player->mo->momx += totalthrust.x;
player->mo->momy += totalthrust.y;
@ -4155,7 +4150,6 @@ static void P_3dMovement(player_t *player)
player->mo->momy = FixedMul(FixedDiv(player->mo->momy, speed), newspeed);
}
}
#endif
// Time to ask three questions:
// 1) Are we over topspeed?