switchMove: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - ": *<code>" to ": <code>")
mNo edit summary
 
(18 intermediate revisions by 4 users not shown)
Line 29: Line 29:


|descr= Immediately applies given animation to the unit. For a smooth transition from the current animation, use [[playMove]].
|descr= Immediately applies given animation to the unit. For a smooth transition from the current animation, use [[playMove]].
{{Feature | Informative | see [[:Category:Moves]] for respective games animations.}}
{{Feature|informative|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).
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 {{HashLink|#Example 3}}).
If an invalid animation is provided, the unit's animations will be reset but no new animation will be played (see {{Link|#Example 3}}).


|mp= This command has global effect when executed locally to the unit and will sync 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 {{HashLink|#Example 2}}). When the argument is remote, the animation change on the executing PC is only temporary.
{{Feature|informative|It is a good practice to always use [[playMoveNow]] after [[switchMove]] to make sure the animation plays correctly when using the first syntax:
<sqf>
_unit switchMove "myMove";
_unit playMoveNow "myMove";
</sqf>
The alternative syntax does this automatically.
}}
 
|mp= 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 {{Link|#Example 2}}).
When the argument is remote, the animation change on the executing PC is only temporary.


|s1= person [[switchMove]] moveName
|s1= person [[switchMove]] moveName
Line 42: Line 54:


|r1= [[Nothing]]
|r1= [[Nothing]]
|s2= person [[switchMove]] [moveName, time, blendFactor, resetAim]
|s2since= arma3 2.18
|p21= person: [[Object]] - unit
|p22= moveName: [[String]] - entry from {{hl|"CfgMovesMaleSdr" >> "states"}} or {{hl|"CfgGesturesMale" >> "states"}}
|p23= time: [[Number]] - (Optional, default 0) normalized time, in range 0..1, where 0 = beginning of the animation, and 1 = end of the animation
|p24= blendFactor: [[Number]] - (Optional, default 1) how much to blend the current animation with the new animation, in range 0..1, where 0 = current animation, and 1 = new animation. When 1 is used, the switching is instant (not smooth), similar to the first syntax.
|p25= resetAim: [[Boolean]] - (Optional, default true) whether the aim/head direction should be reset after switching
|r2= [[Nothing]]


|x1= Prone:
|x1= Prone:
<code>[[player]] [[switchMove]] "AmovPpneMstpSrasWrflDnon";</code>
<sqf>player switchMove "AmovPpneMstpSrasWrflDnon";</sqf>


|x2= Sit player immediately and globally:
|x2= Sit player immediately and globally:
<code>[<nowiki/>[[player]], "AmovPsitMstpSlowWrflDnon"] [[remoteExec]] ["switchMove", 0];</code>
<sqf>[player, "AmovPsitMstpSlowWrflDnon"] remoteExec ["switchMove"];</sqf>


|x3= Resets unit's animation:
|x3= Resets unit's animation:
<code>_unit [[switchMove]] "";</code>
<sqf>_unit switchMove "";</sqf>


|seealso= [[playMove]] [[playMoveNow]] [[switchAction]] [[playAction]] [[playActionNow]]
|x4= <sqf>
// 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];
};
}
</sqf>
 
|seealso= [[switchGesture]] [[playMove]] [[playMoveNow]] [[switchAction]] [[playAction]] [[playActionNow]] [[getUnitMovesInfo]]
}}
}}


<dl class="command_description">
{{Note
|user= Hurricane
|timestamp= 20070325234800
|text= 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.
}}


<dt><dt>
{{Note
<dd class="notedate">Posted on March 25, 2007 - 23:48</dd>
|user= Killswitch
<dt class="note">[[User:Hurricane|Hurricane]]</dt>
|timestamp= 20080803224300
<dd class="note">
|text= This command will not cause an [[ArmA:_Event_Handlers#AnimChanged|AnimChanged]] or [[ArmA:_Event_Handlers#AnimDone|AnimDone]] event. However, [[playMove]] will.
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.
}}
</dd>
 
<dt><dt>
<dd class="notedate">Posted on August 03, 2008 - 22:43</dd>
<dt class="note">[[User:Killswitch|Killswitch]]</dt>
<dd class="note">
This command will not cause an [[ArmA:_Event_Handlers#AnimChanged|AnimChanged]] or [[ArmA:_Event_Handlers#AnimDone|AnimDone]] event. However, [[playMove]] will.
</dd>


<dt><dt>
{{Note
<dd class="notedate">Posted on November 12, 2016 - 20:11 (UTC)</dd>
|user= AgentRevolution
<dt class="note">[[User:AgentRevolution|AgentRev]]</dt>
|timestamp= 20161112201100
<dd class="note">
|text= When using this command on the [[player]] unit outside [[Scheduler#Unscheduled_Environment|unscheduled]] UI contexts, it will cause a minor camera glitch for a single frame.<br>
When using this command on the [[player]] unit outside [[Scheduler#Unscheduled_Environment|unscheduled]] UI contexts, it will cause a minor camera glitch for a single frame.<br>
For example,  [[Arma 3: Mission Event Handlers#Draw3D|Draw3D]] and [[displayAddEventHandler|KeyDown]] are UI contexts and so are not affected by the glitch, but [[Arma 3: Mission Event Handlers#EachFrame|EachFrame]] and [[Scheduler#Scheduled_Environment|scheduled]] scripts are not UI contexts and are affected by the glitch.
For example,  [[Arma 3: Mission Event Handlers#Draw3D|Draw3D]] and [[displayAddEventHandler|KeyDown]] are UI contexts and so are not affected by the glitch, but [[Arma 3: Mission Event Handlers#EachFrame|EachFrame]] and [[Scheduler#Scheduled_Environment|scheduled]] scripts are not UI contexts and are affected by the glitch.
</dd>
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on August 8, 2021 - 15:59 (UTC)</dd>
|user= Leopard20
<dt class="note">[[User:Leopard20|Leopard20]]</dt>
|timestamp= 20210808155900
<dd class="note">
|text= 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:
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:
<sqf>_unit switchMove _move; _unit playMoveNow _move;</sqf>
<code>_unit [[switchMove]] _move; _unit [[playMoveNow]] _move;</code>
This must run in '''[[Scheduler|unscheduled environment]]''' (see [[isNil]])<br/>
This must run in the [[Scheduler|'''unscheduled environment''']] (see [[isNil]])
Alternatively, just use the second syntax:
</dd>
<sqf>_unit switchMove [_move];</sqf>
</dl>
}}

Latest revision as of 15:11, 8 March 2024

Hover & click on the images for description

Description

Description:
Immediately applies given animation to the unit. For a smooth transition from the current animation, use playMove.
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).

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.
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.
Groups:
Animations

Syntax

Syntax:
person switchMove moveName
Parameters:
person: Object - unit
moveName: String - animation state (see animationState)
Return Value:
Nothing

Alternative Syntax

Syntax:
person switchMove [moveName, time, blendFactor, resetAim]
Parameters:
person: Object - unit
moveName: String - entry from "CfgMovesMaleSdr" >> "states" or "CfgGesturesMale" >> "states"
time: Number - (Optional, default 0) normalized time, in range 0..1, where 0 = beginning of the animation, and 1 = end of the animation
blendFactor: Number - (Optional, default 1) how much to blend the current animation with the new animation, in range 0..1, where 0 = current animation, and 1 = new animation. When 1 is used, the switching is instant (not smooth), similar to the first syntax.
resetAim: Boolean - (Optional, default true) whether the aim/head direction should be reset after switching
Return Value:
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]; }; }

Additional Information

See also:
switchGesture playMove playMoveNow switchAction playAction playActionNow getUnitMovesInfo

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Hurricane - c
Posted on Mar 25, 2007 - 23:48 (UTC)
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.
Killswitch - c
Posted on Aug 03, 2008 - 22:43 (UTC)
This command will not cause an AnimChanged or AnimDone event. However, playMove will.
AgentRevolution - c
Posted on Nov 12, 2016 - 20:11 (UTC)
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 - c
Posted on Aug 08, 2021 - 15:59 (UTC)
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];