A_ScaleVelocity
Jump to navigation
Jump to search
Note: This function is effectively deprecated in ZScript, since an actor's vel field can be modified directly, for example: vel *= 0.5 .
|
void A_ScaleVelocity(double scale, int ptr = AAPTR_DEFAULT)
Usage
Multiplies the specified actor's velocity on each axis by scale. It can be used to "speed up" or "slow down" an actor.
By default modifies the calling actor's velocity, but this can be changed with the ptr argument.
Parameters
- double scale
- The value by which to scale the actor's velocity.
- int ptr
- The actor whose velocity to scale. This is an AAPTR actor pointer. Default is AAPTR_DEFAULT, which corresponds to the calling actor.
ZScript definition
Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub. |
void A_ScaleVelocity(double scale, int ptr = AAPTR_DEFAULT)
{
let ref = GetPointer(ptr);
if (ref == NULL)
{
return;
}
bool was_moving = ref.Vel != (0, 0, 0);
ref.Vel *= scale;
// If the actor was previously moving but now is not, and is a player,
// update its player variables. (See A_Stop.)
if (was_moving)
{
ref.CheckStopped();
}
}
(See also GetPointer)
Setting to explicit value
Note, this function can only multiply the actor's current vel
without an ability to set it to an explicit value. To do the latter, you can call, for example, vel = vel.Unit() * <desired speed>
where <desired speed> is a numeric value like 10.
Examples
This lazy rocket slows down and eventually stops.
class LazyRocket : Rocket { States { Spawn: MISL A 1 Bright A_ScaleVelocity(0.95); Loop; } }
In ZScript the same can be achieved without this function:
class LazyRocket : Rocket { States { Spawn: MISL A 1 Bright { vel *= 0.95; } Loop; } }