A ScaleVelocity: Difference between revisions
Jump to navigation
Jump to search
m (removing "new" for GZDoom 2.4.0 release) |
No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:A_ScaleVelocity}} |
{{DISPLAYTITLE:A_ScaleVelocity}} |
||
{{note|This function is effectively [[Deprecation|deprecated]] in [[ZScript]], since an actor's <code>vel</code> field can be modified directly, for example: <code>vel *{{=}} 0.5</code>.}} |
|||
| ⚫ | |||
'''{{class|Actor}}''' |
|||
| ⚫ | |||
==Usage== |
==Usage== |
||
Multiplies the |
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=== |
===Parameters=== |
||
*{{c|double '''scale'''}} |
|||
:The value by which to scale the actor's velocity. |
|||
| ⚫ | |||
*{{c|int '''ptr'''}} |
|||
| ⚫ | |||
== [[ZScript]] definition == |
|||
{{ZScriptDefinitionNote|actors/actions.zs#L35C2-L35C61}} |
|||
<syntaxhighlight lang="csharp"> |
|||
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(); |
|||
} |
|||
}</syntaxhighlight> |
|||
(See also {{c|[[GetPointer]]}}) |
|||
=== Setting to explicit value === |
|||
Note, this function can only multiply the actor's current <code>vel</code> without an ability to set it to an explicit value. To do the latter, you can call, for example, <code>vel = vel.Unit() * <desired speed></code> where <desired speed> is a numeric value like 10. |
|||
== Examples == |
== Examples == |
||
This lazy {{Class|rocket}} slows down and eventually stops. |
This lazy {{Class|rocket}} slows down and eventually stops. |
||
class LazyRocket : {{Class|Rocket}} |
|||
{ |
|||
States |
|||
{ |
|||
Spawn: |
|||
MISL A 1 Bright [[A_ScaleVelocity]](0.95); |
|||
Loop; |
|||
} |
|||
} |
|||
In ZScript the same can be achieved without this function: |
|||
class LazyRocket : {{Class|Rocket}} |
|||
{ |
{ |
||
States |
States |
||
{ |
{ |
||
Spawn: |
Spawn: |
||
MISL A 1 Bright |
MISL A 1 Bright { vel *= 0.95; } |
||
Loop |
Loop; |
||
} |
} |
||
} |
} |
||
[[Category:ZScript]] |
|||
{{DEFAULTSORT:ScaleVelocity}}[[category:Decorate Status change functions]] |
{{DEFAULTSORT:ScaleVelocity}}[[category:Decorate Status change functions]] |
||
Latest revision as of 11:48, 29 April 2025
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 UZDoom. The most up-to-date version of this code can be found on UZDoom 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; } }