Rewrite T_PolyObjWaypoint to move more smoothly
This commit is contained in:
parent
0508f99419
commit
e422d1fa1d
|
@ -1600,11 +1600,8 @@ static void T_MovePolyObj(polyobj_t *po, fixed_t distx, fixed_t disty, fixed_t d
|
||||||
void T_PolyObjWaypoint(polywaypoint_t *th)
|
void T_PolyObjWaypoint(polywaypoint_t *th)
|
||||||
{
|
{
|
||||||
mobj_t *target = NULL;
|
mobj_t *target = NULL;
|
||||||
mobj_t *waypoint = NULL;
|
|
||||||
fixed_t pox, poy, poz;
|
|
||||||
fixed_t distx, disty, distz, dist;
|
|
||||||
fixed_t momx, momy, momz;
|
|
||||||
polyobj_t *po = Polyobj_GetForNum(th->polyObjNum);
|
polyobj_t *po = Polyobj_GetForNum(th->polyObjNum);
|
||||||
|
fixed_t speed = th->speed;
|
||||||
|
|
||||||
if (!po)
|
if (!po)
|
||||||
#ifdef RANGECHECK
|
#ifdef RANGECHECK
|
||||||
|
@ -1629,6 +1626,14 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move along the waypoint sequence until speed for the current tic is exhausted
|
||||||
|
while (speed > 0)
|
||||||
|
{
|
||||||
|
mobj_t *waypoint = NULL;
|
||||||
|
fixed_t pox, poy, poz;
|
||||||
|
fixed_t distx, disty, distz, dist;
|
||||||
|
|
||||||
|
// Current position of polyobject
|
||||||
pox = po->centerPt.x;
|
pox = po->centerPt.x;
|
||||||
poy = po->centerPt.y;
|
poy = po->centerPt.y;
|
||||||
poz = (po->lines[0]->backsector->floorheight + po->lines[0]->backsector->ceilingheight)/2;
|
poz = (po->lines[0]->backsector->floorheight + po->lines[0]->backsector->ceilingheight)/2;
|
||||||
|
@ -1642,15 +1647,21 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
|
||||||
if (dist < 1)
|
if (dist < 1)
|
||||||
dist = 1;
|
dist = 1;
|
||||||
|
|
||||||
momx = FixedMul(FixedDiv(target->x - pox, dist), th->speed);
|
// Will the polyobject overshoot its target?
|
||||||
momy = FixedMul(FixedDiv(target->y - poy, dist), th->speed);
|
if (speed <= dist)
|
||||||
momz = FixedMul(FixedDiv(target->z - poz, dist), th->speed);
|
|
||||||
|
|
||||||
// Will the polyobject be FURTHER away if the momx/momy/momz is added to
|
|
||||||
// its current coordinates, or closer? (shift down to fracunits to avoid approximation errors)
|
|
||||||
if (dist>>FRACBITS <= P_AproxDistance(P_AproxDistance(target->x - pox - momx, target->y - poy - momy), target->z - poz - momz)>>FRACBITS)
|
|
||||||
{
|
{
|
||||||
// If further away, set XYZ of polyobject to waypoint location
|
// No. Move towards waypoint
|
||||||
|
fixed_t momx, momy, momz;
|
||||||
|
|
||||||
|
momx = FixedMul(FixedDiv(target->x - pox, dist), speed);
|
||||||
|
momy = FixedMul(FixedDiv(target->y - poy, dist), speed);
|
||||||
|
momz = FixedMul(FixedDiv(target->z - poz, dist), speed);
|
||||||
|
T_MovePolyObj(po, momx, momy, momz);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Yes. Teleport to waypoint and look for the next one
|
||||||
T_MovePolyObj(po, distx, disty, distz);
|
T_MovePolyObj(po, distx, disty, distz);
|
||||||
|
|
||||||
if (!th->stophere)
|
if (!th->stophere)
|
||||||
|
@ -1688,21 +1699,11 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
|
||||||
// Set the mobj as your target! -- Monster Iestyn 27/12/19
|
// Set the mobj as your target! -- Monster Iestyn 27/12/19
|
||||||
P_SetTarget(&th->target, target);
|
P_SetTarget(&th->target, target);
|
||||||
|
|
||||||
// calculate MOMX/MOMY/MOMZ for next waypoint
|
// Calculate remaining speed
|
||||||
// change slope
|
speed -= dist;
|
||||||
dist = P_AproxDistance(P_AproxDistance(target->x - pox, target->y - poy), target->z - poz);
|
|
||||||
|
|
||||||
if (dist < 1)
|
|
||||||
dist = 1;
|
|
||||||
|
|
||||||
momx = FixedMul(FixedDiv(target->x - pox, dist), th->speed);
|
|
||||||
momy = FixedMul(FixedDiv(target->y - poy, dist), th->speed);
|
|
||||||
momz = FixedMul(FixedDiv(target->z - poz, dist), th->speed);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
momx = momy = momz = 0;
|
|
||||||
|
|
||||||
if (!th->stophere)
|
if (!th->stophere)
|
||||||
CONS_Debug(DBG_POLYOBJ, "Next waypoint not found!\n");
|
CONS_Debug(DBG_POLYOBJ, "Next waypoint not found!\n");
|
||||||
|
|
||||||
|
@ -1713,13 +1714,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// momx/momy/momz already equals the right speed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the polyobject
|
|
||||||
T_MovePolyObj(po, momx, momy, momz);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_PolyDoorSlide(polyslidedoor_t *th)
|
void T_PolyDoorSlide(polyslidedoor_t *th)
|
||||||
|
|
Loading…
Reference in a new issue