setDir: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (template:command argument fix)
m (Added additional example)
 
(46 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| ofp |= Game name
|game1= ofp
|version1= 1.00


|1.00|= Game version
|game2= ofpe
|version2= 1.00


|arg= local |Multiplayer Arguments=
|game3= arma1
|version3= 1.00


|eff= global |Multiplayer Effects=
|game4= arma2
____________________________________________________________________________________________
|version4= 1.00


| Sets object heading. Angles are measured in degrees clockwise from north, and regular range goes from 0 to 360 (0° {{=}} N, 90° {{=}} E, 180° {{=}} S, 270° {{=}} W). Negative angles represent a counter-clockwise angle. |DESCRIPTION=
|game5= arma2oa
____________________________________________________________________________________________
|version5= 1.50


| object '''setDir''' heading |SYNTAX=
|game6= tkoh
|version6= 1.00


|p1= object: [[Object]] |PARAMETER1=
|game7= arma3
|p2= heading: [[Number]] |PARAMETER2=
|version7= 0.50


| [[Nothing]] |RETURNVALUE=
|arg= local
____________________________________________________________________________________________
|eff= global


|x1 = <code>unit1 [[setDir]] 45; {{codecomment|// will set unit1 to face North-East}}</code>
|gr1= Object Manipulation


|x2 = <code>unit1 [[setDir]] -675; {{codecomment|// will also set unit1 to face North-East ({{=}} 45-360-360)}}</code>
|descr= Sets object heading. Angles are measured in degrees clockwise from north; the regular range goes from 0 to 360 (0° = N, 90° = E, 180° = S, 270° = W). Negative angles represent counter-clockwise angles.
{{Feature|important|This command resets the object's [[velocity]] and [[vectorUp]]!}}
{{Feature|informative|In ''some'' earlier titles ({{ofp}}?), this command was {{Icon|localEffect|32}}.}}


|x3 = <code>unit1 [[setDir]] 30;
|pr= <nowiki/>
unit1 [[setFormDir]] 30;{{codecomment|// needed for AI to keep the given direction}}</code>
* The effect is {{Icon|localEffect|32}} when using [[setDir]] on a mine. Use a position modification to broadcast [[setDir]]'s change (see {{Link|#Example 4}})
* setting direction ''after'' position may lead to weird behaviours - see {{Link|#Notes}}


| [[getDir]], [[direction]], [[setFormDir]], [[setVectorDir]], [[setVectorDirAndUp]] |SEEALSO=
|mp= See the {{Link|#Notes}} below


|mp= See notes below for more details on [[setDir]] behaviour. |= Multiplayer
|s1= object [[setDir]] heading


}}
|p1= object: [[Object]]


<h3 style="display:none">Notes</h3>
|p2= heading: [[Number]]
<dl class="command_description">
<!-- Note Section BEGIN -->


|r1= [[Nothing]]


<dd class="notedate">Posted on May 9, 2007 - 20:43 CET
|x1= <sqf>myUnit setDir 45; // will set myUnit to face North-East</sqf>
<dt class="note">[[User:Manny|Manny]]
<dd class="note">
Though effects of this command remain local, you can do a [[setPos]] afterwards to synchronize the direction on all machines in MP.
<code>myObj [[setDir]] 90;
myObj [[setPos]] [[getPos]] myObj;</code>


|x2= <sqf>myUnit setDir -675; // will also set myUnit to face North-East (= 45-360-360)</sqf>


<dd class="notedate">Posted on January 9, 2009 - 22:21
|x3= <sqf>
<dt class="note">[[User:Killswitch|Killswitch]]
MyUnit setDir 30;
<dd class="note">
MyUnit setFormDir 30; // needed for AI to keep the given direction
In ArmA, the effect of [[setDir]] is synchronized across the network.
</sqf>


|x4= <sqf>
// provided _myMine is local
_myMine setDir 45;
_myMine setPosWorld getPosWorld _myMine;


<dd class="notedate">Posted on April 5th, 2011
// or
<dt class="note">[[User:kju|kju]]
[_myMine, 45] remoteExec ["setDir"];
<dd class="note">
</sqf>
In OA 1.59 the comment of Manny still holds true for [[createVehicle]]'d empty vehicles by the server.
For the player object a local [[setDir]] alone is enough.


|x5= <sqf>
// Sets the direction of an object relative to a parent object's direction
_child setDir (_parentDir + (_childDir - _parentDir))
</sqf>


<dd class="notedate">Posted on November 25, 2013
|seealso= [[getDir]] [[direction]] [[setFormDir]] [[setVectorDir]] [[setVectorDirAndUp]]
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]
<dd class="note">
In Arma 3, [[setDir]] affects [[vectorUp]], [[vectorDir]] and [[velocity]] of the object it applied to. While this is not noticeable with stationary objects, a moving objects will have its orientation and velocity reset. So if you are planning on using [[setDir]] on a moving object, make sure you read the velocity value before and restore it after if you want the object to continue to move.
<code>_vel = [[velocity]] _object;
_object [[setDir]] 45;
_object [[setVelocity]] _vel;</code>
With orientation it is a bit more complicated. [[setDir]] resets [[vectorUp]] to [0,0,1] and changes [[vectorDir]] accordingly to accommodate set direction. If your object's [[vectorUp]] is not [0,0,1] and you want to keep it this way, then you have to use [[setVectorDirAndUp]] to change object's direction not [[setDir]]. This is also the reason why it is better to use [[setVectorDirAndUp]] instead of [[setDir]] on attached objects for a better control of object's orientation.


}}


<dd class="notedate">Posted on November 27, 2013
{{Note
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]
|user= Manny
<dd class="note">
|timestamp= 20070509204300
Make sure you [[setDir]] BEFORE you set position. '''Setting direction after set position could lead to unpredictable behaviour'''. For example main part of the hospital building in Arma 3 can lose collision detection near both side entrances. AI will also get confused and will stop detecting obstacles if [[setDir]] is called after [[setPos]].
|text= Though effects of this command remain local, you can do a [[setPos]] afterwards to synchronize the direction on all machines in MP.
<sqf>
myObj setDir 90;
myObj setPos getPos myObj;
</sqf>
|game= arma1
}}


{{Note
|user= .kju
|timestamp= 20010405105400
|text= In {{arma2oa}} 1.59 the comment of Manny still holds true for [[createVehicle]]'d empty vehicles by the server.
For the player object a local [[setDir]] alone is enough.
}}


<dd class="notedate">Posted on February 9, 2018 - 14:57 (UTC)
{{Note
<dt class="note">[[User:Tankbuster|Tankbuster]]
|user= Killzone_Kid
<dd class="note">
|timestamp= 20131125114700
[[setDir]] is not propagated across the network when used on mines. Clients will see mines facing zero. This is especially noticeable on tripwire mines.<br>
|text= In {{arma3}}, [[setDir]] affects [[vectorUp]], [[vectorDir]] and [[velocity]] of the object it applied to. While this is not noticeable with stationary objects, a moving objects will have its orientation and velocity reset. So if you are planning on using [[setDir]] on a moving object, make sure you read the velocity value before and restore it after if you want the object to continue to move.
Use [[remoteExec]] to run the [[setDir]] command on the mine for all clients.
<sqf>
_vel = velocity _object;
_object setDir 45;
_object setVelocity _vel;
</sqf>
With orientation it is a bit more complicated. [[setDir]] resets [[vectorUp]] to [0,0,1] and changes [[vectorDir]] accordingly to accommodate set direction. If your object's [[vectorUp]] is not [0,0,1] and you want to keep it this way, then you have to use [[setVectorDirAndUp]] to change object's direction not [[setDir]]. This is also the reason why it is better to use [[setVectorDirAndUp]] instead of [[setDir]] on attached objects for a better control of object's orientation.
}}


 
{{Note
<!-- Note Section END -->
|user= Killzone_Kid
</dl>
|timestamp= 20131127230900
 
|text= Make sure you [[setDir]] BEFORE you set position. '''Setting direction after set position could lead to unpredictable behaviour'''. For example main part of the hospital building in Arma 3 can lose collision detection near both side entrances. AI will also get confused and will stop detecting obstacles if [[setDir]] is called after [[setPos]].
<h3 style="display:none">Bottom Section</h3>
}}
[[Category:Scripting Commands|SETDIR]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|SETDIR]]
[[Category:Scripting Commands OFP 1.46|SETDIR]]
[[Category:Scripting Commands ArmA|SETDIR]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Latest revision as of 03:04, 12 May 2024

Hover & click on the images for description

Description

Description:
Sets object heading. Angles are measured in degrees clockwise from north; the regular range goes from 0 to 360 (0° = N, 90° = E, 180° = S, 270° = W). Negative angles represent counter-clockwise angles.
This command resets the object's velocity and vectorUp!
In some earlier titles (Operation Flashpoint?), this command was LELocal.
Multiplayer:
See the Notes below
Problems:
  • The effect is LELocal when using setDir on a mine. Use a position modification to broadcast setDir's change (see Example 4)
  • setting direction after position may lead to weird behaviours - see Notes
Groups:
Object Manipulation

Syntax

Syntax:
object setDir heading
Parameters:
object: Object
heading: Number
Return Value:
Nothing

Examples

Example 1:
myUnit setDir 45; // will set myUnit to face North-East
Example 2:
myUnit setDir -675; // will also set myUnit to face North-East (= 45-360-360)
Example 3:
MyUnit setDir 30; MyUnit setFormDir 30; // needed for AI to keep the given direction
Example 4:
// provided _myMine is local _myMine setDir 45; _myMine setPosWorld getPosWorld _myMine; // or [_myMine, 45] remoteExec ["setDir"];
Example 5:
// Sets the direction of an object relative to a parent object's direction _child setDir (_parentDir + (_childDir - _parentDir))

Additional Information

See also:
getDir direction setFormDir setVectorDir setVectorDirAndUp

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
Manny - c
Posted on May 09, 2007 - 20:43 (UTC)

Though effects of this command remain local, you can do a setPos afterwards to synchronize the direction on all machines in MP.

myObj setDir 90; myObj setPos getPos myObj;

.kju - c
Posted on Apr 05, 2001 - 10:54 (UTC)
In Arma 2: Operation Arrowhead 1.59 the comment of Manny still holds true for createVehicle'd empty vehicles by the server. For the player object a local setDir alone is enough.
Killzone_Kid - c
Posted on Nov 25, 2013 - 11:47 (UTC)
In Arma 3, setDir affects vectorUp, vectorDir and velocity of the object it applied to. While this is not noticeable with stationary objects, a moving objects will have its orientation and velocity reset. So if you are planning on using setDir on a moving object, make sure you read the velocity value before and restore it after if you want the object to continue to move.
_vel = velocity _object; _object setDir 45; _object setVelocity _vel;
With orientation it is a bit more complicated. setDir resets vectorUp to [0,0,1] and changes vectorDir accordingly to accommodate set direction. If your object's vectorUp is not [0,0,1] and you want to keep it this way, then you have to use setVectorDirAndUp to change object's direction not setDir. This is also the reason why it is better to use setVectorDirAndUp instead of setDir on attached objects for a better control of object's orientation.
Killzone_Kid - c
Posted on Nov 27, 2013 - 23:09 (UTC)
Make sure you setDir BEFORE you set position. Setting direction after set position could lead to unpredictable behaviour. For example main part of the hospital building in Arma 3 can lose collision detection near both side entrances. AI will also get confused and will stop detecting obstacles if setDir is called after setPos.