mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-26 12:01:47 +00:00
Help reduce waypoint flickering by using closest waypoint to finish line
This commit is contained in:
parent
15bda7da2d
commit
2e4b1c6ecb
1 changed files with 31 additions and 1 deletions
|
|
@ -270,9 +270,12 @@ waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
||||||
waypoint_t *checkwaypoint = NULL;
|
waypoint_t *checkwaypoint = NULL;
|
||||||
fixed_t closestdist = INT32_MAX;
|
fixed_t closestdist = INT32_MAX;
|
||||||
fixed_t checkdist = INT32_MAX;
|
fixed_t checkdist = INT32_MAX;
|
||||||
|
fixed_t bestfindist = INT32_MAX;
|
||||||
|
|
||||||
for (i = 0; i < numwaypoints; i++)
|
for (i = 0; i < numwaypoints; i++)
|
||||||
{
|
{
|
||||||
|
fixed_t rad;
|
||||||
|
|
||||||
checkwaypoint = &waypointheap[i];
|
checkwaypoint = &waypointheap[i];
|
||||||
|
|
||||||
checkdist = P_AproxDistance(
|
checkdist = P_AproxDistance(
|
||||||
|
|
@ -280,7 +283,34 @@ waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
||||||
(mobj->y / FRACUNIT) - (checkwaypoint->mobj->y / FRACUNIT));
|
(mobj->y / FRACUNIT) - (checkwaypoint->mobj->y / FRACUNIT));
|
||||||
checkdist = P_AproxDistance(checkdist, ((mobj->z / FRACUNIT) - (checkwaypoint->mobj->z / FRACUNIT)) * 4);
|
checkdist = P_AproxDistance(checkdist, ((mobj->z / FRACUNIT) - (checkwaypoint->mobj->z / FRACUNIT)) * 4);
|
||||||
|
|
||||||
if (checkdist < closestdist)
|
rad = (checkwaypoint->mobj->radius / FRACUNIT);
|
||||||
|
|
||||||
|
if (closestdist < rad && checkdist < rad && finishline != NULL)
|
||||||
|
{
|
||||||
|
const boolean useshortcuts = false;
|
||||||
|
const boolean huntbackwards = false;
|
||||||
|
boolean pathfindsuccess = false;
|
||||||
|
path_t pathtofinish = {};
|
||||||
|
|
||||||
|
// If the mobj is touching multiple waypoints at once,
|
||||||
|
// then solve ties by taking the one closest to the finish line.
|
||||||
|
// Prevents position from flickering wildly when taking turns.
|
||||||
|
|
||||||
|
pathfindsuccess =
|
||||||
|
K_PathfindToWaypoint(checkwaypoint, finishline, &pathtofinish, useshortcuts, huntbackwards);
|
||||||
|
|
||||||
|
if (pathfindsuccess == true)
|
||||||
|
{
|
||||||
|
if ((INT32)(pathtofinish.totaldist) < bestfindist)
|
||||||
|
{
|
||||||
|
bestwaypoint = checkwaypoint;
|
||||||
|
bestfindist = pathtofinish.totaldist;
|
||||||
|
}
|
||||||
|
|
||||||
|
Z_Free(pathtofinish.array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (checkdist < closestdist && bestfindist == INT32_MAX)
|
||||||
{
|
{
|
||||||
if (!P_CheckSight(mobj, checkwaypoint->mobj))
|
if (!P_CheckSight(mobj, checkwaypoint->mobj))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue