A_ChangeVelocity

From ZDoom Wiki
Jump to navigation Jump to search

A_ChangeVelocity [(float x [, float y [, float z [, int flags [, int ptr]]]])]

Usage

Changes the calling actor's or the pointed to actor velocity on each axis. If the "relative axes" flag is set, the "x" argument will represent forward and backward movement and the "y" argument will represent side-to-side movement. If the "replace old velocity" flag is set, the actor's velocity will be set to the new velocity; otherwise, the new velocity will be added to the old velocity. Negative values indicate movement backwards, right, and down respectively.

Parameters

  • x: velocity on x axis (or forward and backward). Default is 0.
  • y: velocity on y axis (or side to side). Default is 0.
  • z: velocity on z axis (up and down). Default is 0.
  • flags: The following flags can be combined by using the | character between the constant names:
    • CVF_RELATIVE — Relative axes: Make x, y relative to actor's current angle.
    • CVF_REPLACE — Replace old velocity: Replace old velocity with new velocity.
  • ptr: The actor to change its velocity. This is an actor pointer. Default is AAPTR_DEFAULT, which corresponds to the calling actor.

Examples

This makes the rocket go forward twice as fast without changing the speed at which it falls/ascends.

Totally breaks it's vertical path (off the crosshair), so don't use this for things that don't fall down or are otherwise vertically unstable. (Or do, but not as blatantly.):

ACTOR TurboRocket : Rocket
{
  States
  {  
  Spawn:
    TNT1 A 0
    MISL A -1 A_ChangeVelocity(velx*2, vely*2, velz, CVF_REPLACE)
    //We do this by getting the appropriate velocities (x/y of velx/y/z) and multiplying them by 2,
    //and replacing the old ones. 
    //Do note that this causes the rocket to not follow the crosshair. So it's best suited for things
    //that already fall do not follow it. (Like grenades)
    Stop
  }
}

This is a boomerang-style projectile that reverses direction after traveling a set distance, then enters its Death state after making the return trip (assuming it doesn't hit anything along the way):

ACTOR BoomerangBall : PlasmaBall
{
  States
  {
  Spawn:
    PLSS AB 6 Bright
    PLSS A 0 A_ChangeVelocity (-25, 0, -velz, CVF_RELATIVE|CVF_REPLACE)
    //Entering "-velx" does not function correctly, so use proper numbers for reversal.
    PLSS AB 6 Bright
  Death:
    PLSE ABCDE 4 Bright
    Stop
  }
}

See also

For a less complicated way to modify an actor's velocity, try A_ScaleVelocity.