A_HomingChase is an action that makes the actor move directly towards its target/tracer Object in all directions, in a similar fashion to how rings follow players equipped with an Attraction Shield. This action should be called every tic for the chasing behavior to function properly. Var1 determines the movement speed (should be a multiple of FRACUNIT
), and Var2 determines the Object to chase (0 = target, 1 = tracer). The actor's angle is adjusted to face the Object it is chasing. If the Object to chase does not exist or has no health, this action will do nothing.
Code – A_HomingChase
|
|
// Function: A_HomingChase
//
// Description: Actor chases directly towards its destination object
//
// var1 = speed multiple
// var2 = destination: 0 = target, 1 = tracer
//
void A_HomingChase(mobj_t *actor)
{
INT32 locvar1 = var1;
INT32 locvar2 = var2;
mobj_t *dest;
fixed_t dist;
fixed_t speedmul;
#ifdef HAVE_BLUA
if (LUA_CallAction("A_HomingChase", actor))
return;
#endif
if (locvar2 == 1)
dest = actor->tracer;
else //default
dest = actor->target;
if (!dest || !dest->health)
return;
actor->angle = R_PointToAngle2(actor->x, actor->y, dest->x, dest->y);
dist = P_AproxDistance(P_AproxDistance(dest->x - actor->x, dest->y - actor->y), dest->z - actor->z);
if (dist < 1)
dist = 1;
speedmul = FixedMul(locvar1, actor->scale);
actor->momx = FixedMul(FixedDiv(dest->x - actor->x, dist), speedmul);
actor->momy = FixedMul(FixedDiv(dest->y - actor->y, dist), speedmul);
actor->momz = FixedMul(FixedDiv(dest->z - actor->z, dist), speedmul);
}
|
|