A_ScaleVelocity

From ZDoom Wiki
Jump to navigation Jump to search

Actor

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 scale, but this can be changed with the ptrargument.

In ZScript this function is largely moot since the actor's vel field can be modified directly, for example vel *= 0.5.

Parameters

  • double scale
The value by which to scale the actor's velocity.
  • int ptr
The actor to scale its velocity. This is an 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)

Examples

This lazy rocket slows down and eventually stops.

class LazyRocket : Rocket
{
  States
  {  
  Spawn:
    MISL A 1 Bright A_ScaleVelocity(0.95);
    Loop;
  }
}