Arma 3 Scripting

Command in Animations

switchMove

Also available as Markdown and JSON, or read the original wiki page.

Description

Immediately applies given animation to the unit. For a smooth transition from the current animation (by connecting animations successively, e.g CurrentAnim -> Intermediate1 -> Intermediate2 -> TargetAnim), use playMove or playMoveNow.

Note

see Category:Moves for respective games animations.

This command first resets the unit's animation states (including aiming state, gesture state, etc.) then puts the unit in the first frame of the animation (therefore showing no transition). If an invalid animation is provided, the unit's animations will be reset but no new animation will be played (see #Example 3).

Note

It is a good practice to always use playMoveNow after switchMove to make sure the animation plays correctly when using the first syntax:

_unit switchMove "myMove";
_unit playMoveNow "myMove";

The alternative syntax does this automatically.

Syntax

Syntax 1

person switchMove moveName

Parameters:

Returns: Nothing

Syntax 2

since arma3 2.18

person switchMove [moveName, time, blendFactor, resetAim]

Parameters:

Returns: Nothing

Examples

Example 1

Prone:

player switchMove "AmovPpneMstpSrasWrflDnon";

Example 2

Sit player immediately and globally:

[player, "AmovPsitMstpSlowWrflDnon"] remoteExec ["switchMove"];

Example 3

Resets unit's animation:

_unit switchMove "";

Example 4

// Create a dummy agent that copies your moves
ai1 = createAgent [typeOf player, getPosATL player, [], 0, "NONE"];
ai1 disableAI "ALL";
onEachFrame
{
    ai1 setAnimSpeedCoef getAnimSpeedCoef player;
    ai1 setVectorDir vectorDir player;
    private _m = animationState player;
    private _g = gestureState player;
    private _i = getUnitMovesInfo player;
    private _a = getUnitMovesInfo ai1;
    
    if (animationState ai1 != _m || abs(_i#1 - _a#1) > 0.1) then
    {
        ai1 switchMove [_m, _i#0, _i#3, false];
    };

    if ((gestureState ai1 != _g || abs(_i#6 - _a#6) > 0.1) && (_g != "<none>" && _g find "_player" < 0)) then
    {
        ai1 switchGesture [_g, _i#5, _i#8, false];
    };
}

Multiplayer

This command has a global effect when executed locally to the unit and will synchronise properly for JIP. In this case the animation on the executing machine is immediate while on remote machines it will be transitional. In order for the animation to change immediately on every PC in multiplayer, use global remote execution (see #Example 2). When the argument is remote, the animation change on the executing PC is only temporary.

See also

switchGesture · playMove · playMoveNow · switchAction · playAction · playActionNow · animationState · getUnitMovesInfo

Community notes

Hurricane

In some cases the movement won't stay. I.e. AI hostages that put their hands behind their heads (_hostage switchMove "AmovPercMstpSsurWnonDnon") won't hold their hands up, unless you first use disableAI "autoTarget" on them. They mostly put their hands down because they 'noticed' unknown objects.

AgentRev

When using this command on the player unit outside unscheduled UI contexts, it will cause a minor camera glitch for a single frame.

For example, Draw3D and KeyDown are UI contexts and so are not affected by the glitch, but EachFrame and scheduled scripts are not UI contexts and are affected by the glitch.

Leopard20

If the animation you're trying to use with this command has no connection/interpolation to the unit's base animation (usually "AmovPercMstpSrasWrflDnon"), the move might not play using switchMove alone. In such cases you have to do this:

_unit switchMove _move; _unit playMoveNow _move;

This must run in unscheduled environment (see isNil)

Alternatively, just use the second syntax:

_unit switchMove [_move];
Leopard20

You can loop an animation using a function like this (it's recommended to do ai disableAI "ANIM" first)

// TAG_fnc_loopAnim
params ["_unit", "_anim"];

// remove old EH
_unit removeEventHandler ["AnimStateChanged", _unit getVariable ["TAG_AnimStateChangedEH", -1]];

private _EH = -1;
// if anim is empty, just stop looping
if (_anim != "") then
{
    _EH = _unit addEventHandler ["AnimStateChanged", {  
        params ["_unit", "_anim"]; 
        private _loopedAnim = _unit getVariable ["TAG_LoopedAnim", ""];
        if (alive _unit && _anim != _loopedAnim) then {
            _unit switchMove [_loopedAnim, 0, 0, false];
        };
    }];
};

_unit setVariable ["TAG_AnimStateChangedEH", _EH];
_unit setVariable ["TAG_LoopedAnim", _anim];

// start the anim
_unit switchMove [_anim, 0, 0, false];

Then use the above code in a function, either by defining it in the function library or by doing

TAG_fnc_loopAnim = { above code }

How to use the function:

// start looping
[testUnit, "HubSittingChairUA_move1"] call TAG_fnc_loopAnim;

// stop looping
[testUnit, ""] call TAG_fnc_loopAnim;