---
name: "setVectorDirAndUp"
type: command
status: ok
groups: ["Math - Vectors"]
arma3_since: "0.50"
locality: {"argument": "local", "effect": "global", "server_exec": false}
source: https://community.bistudio.com/wiki/setVectorDirAndUp
revid: 378407
updated: 2026-04-04T08:14:53Z
---

# setVectorDirAndUp

*Command · Math - Vectors · Arma 3 v0.50 · introduced in Armed Assault v1.09*

Locality: arguments **local** · effect **global**

## Description

Sets orientation of an object.
The command takes 2 vector arrays, one for [vectorDir](../commands/vectorDir.md) and one for [vectorUp](../commands/vectorUp.md).
Default object orientation will always have [vectorDir](../commands/vectorDir.md) pointing forward (North) along Y axis and [vectorUp](../commands/vectorUp.md) pointing up along Z axis - [[0,1,0],[0,0,1]], as shown on the diagram below (see also [BIS_fnc_transformVectorDirAndUp](../functions/BIS_fnc_transformVectorDirAndUp.md)).

When attaching object to an object the axes are relative to the object that gets the attachment.
If it is player object for example, then X goes from left to right, Y goes from back to front, and Z goes from down up.

The [setDir](../commands/setDir.md) command is incompatible with [setVectorDirAndUp](../commands/setVectorDirAndUp.md) and should not be used together on the same object.
Using [setVectorDirAndUp](../commands/setVectorDirAndUp.md) alone should be sufficient for any orientation.

## Syntax

```sqf
vehicle setVectorDirAndUp [vectorDir, vectorUp]
```

**Parameters:**

- `vehicle`: [Object](../topics/Object.md)
- `vectorDir`: [Vector3D](../topics/Vector3D.md) - [vectorDir](../commands/vectorDir.md)
- `vectorUp`: [Vector3D](../topics/Vector3D.md) - [vectorUp](../commands/vectorUp.md)

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
// set exact yaw, pitch, and roll
_yaw = 45; _pitch = -80; _roll = 0;
_myObject setVectorDirAndUp [
    [sin _yaw * cos _pitch, cos _yaw * cos _pitch, sin _pitch],
    [[sin _roll, -sin _pitch, cos _roll * cos _pitch], -_yaw] call BIS_fnc_rotateVector2D
];
```

### Example 2

To rotate _myObject on Z axis 90 degrees clockwise, change its [vectorDir](../commands/vectorDir.md) but leave [vectorUp](../commands/vectorUp.md) unchanged.

```sqf
_myObject setVectorDirAndUp [[1,0,0], [0,0,1]];
```

### Example 3

To rotate _myObject on Y axis 90 degrees clockwise, change its [vectorUp](../commands/vectorUp.md) but leave [vectorDir](../commands/vectorDir.md) unchanged.

```sqf
_myObject setVectorDirAndUp [[0,1,0], [1,0,0]];
```

### Example 4

To rotate _myObject on X axis 90 degrees (tilt forward), change both [vectorDir](../commands/vectorDir.md) and [vectorUp](../commands/vectorUp.md) accordingly.

```sqf
_myObject setVectorDirAndUp [[0,0,-1], [0,1,0]];
```

### Example 5

More complex orientations

```sqf
// tilt forward 90 + rotate left 90
_myObject setVectorDirAndUp [[1,0,0], [0,1,0]];
// tilt backward 45 degrees
_myObject setVectorDirAndUp [[0,0.5,0.5], [0,-0.5,0.5]];
// tilt forward 30 degrees
_myObject setVectorDirAndUp [[0,0.66,-0.33], [0,0.33,0.66]];
```

## See also

[vectorDir](../commands/vectorDir.md) · [vectorUp](../commands/vectorUp.md) · [setVectorDir](../commands/setVectorDir.md) · [setVectorUp](../commands/setVectorUp.md) · [vectorDiff](../commands/vectorDiff.md) · [vectorAdd](../commands/vectorAdd.md) · [vectorMultiply](../commands/vectorMultiply.md) · [vectorCrossProduct](../commands/vectorCrossProduct.md) · [vectorDistance](../commands/vectorDistance.md) · [vectorMagnitudeSqr](../commands/vectorMagnitudeSqr.md) · [vectorDistanceSqr](../commands/vectorDistanceSqr.md) · [vectorCos](../commands/vectorCos.md) · [vectorMagnitude](../commands/vectorMagnitude.md) · [vectorDotProduct](../commands/vectorDotProduct.md) · [vectorNormalized](../commands/vectorNormalized.md) · [vectorFromTo](../commands/vectorFromTo.md) · [BIS_fnc_transformVectorDirAndUp](../functions/BIS_fnc_transformVectorDirAndUp.md)

## Community notes

**Str** — 2008-03-16

Command can be also used to rotate camera in all three axis (which also mean it is possible to set camera bank).

---

**General Barron** — 2008-05-09

The object's vectorDir can only control its pitch, while its vectorUp can only control its bank. To set an object's yaw (direction), use the setdir command, before using this command.
You would think vectorUp would control pitch as well, but any pitch that would be set due to vectorUp is ignored. The same is true with vectorDir and yaw; any vectorDir that would adjust yaw is also ignored. If this doesn't make sense, try to visualize it with a box or soda can.
This command does NOT work with values relative to a unit, but rather it works with world vectors (think world coordinates as opposed to model coordinates). As a result, this command can be difficult to use in many situations, because the input values needed to get a certain pitch / bank for an object vary, depending on what direction the object is facing (yaw).
A function to set an object's pitch / bank can be found [](../commands/setVectorDirAndUp.md)

---

**Chris330** — 2009-10-23

Note this odd command may now be better understood. There's a thread about it here:
[](../commands/setVectorDirAndUp.md)

---

**ffur2007slx2_5** — 2014-06-01

Arma 3 v1.20 [setDir](../commands/setDir.md) overwrites [setVectorDirAndUp](../commands/setVectorDirAndUp.md) (P.S. [setVectorDirAndUp](../commands/setVectorDirAndUp.md) also affects [setVelocity](../commands/setVelocity.md).), so use [setDir](../commands/setDir.md) before [BIS_fnc_setPitchBank](../functions/BIS_fnc_setPitchBank.md), which is an easier workaround on vector, if changing yaw, pitch and bank are needed. [setVectorDirAndUp](../commands/setVectorDirAndUp.md) is CCW, so if we wanna to set an obj 40 degrees CW, 170 degrees pitch and 85 degrees bank:

```sqf
_obj setDir (40 - 180); [_obj, 170, 85] call BIS_fnc_setPitchBank;
```

Same as:

```sqf
_obj setVectorDirAndUp [[0.63,0.75,0.17],[-0.75,0.65,-0.084]];
```

Be aware that [attachTo](../commands/attachTo.md) may flip [vectorDir](../commands/vectorDir.md) if pitch beyond 90 degrees and cause unexpected behavior to [BIS_fnc_setPitchBank](../functions/BIS_fnc_setPitchBank.md), e.g.

```sqf
[_obj, 100, 0] call BIS_fnc_setPitchBank; // vector: [-0.14,-0.09,0.98],[-0.83,-0.51,-0.17]
```

```sqf
_obj attachTo [_logic,[0,0,2]];
[_obj, 100, 0] call BIS_fnc_setPitchBank; // vector: [0.11,0.33,0.93],[-0.06,0.94,-0.32]
```

compass direction algorithm failed if obj was attached at present.
To overcome such limitation we can use fallowing function for a better workaround. (code originated from '''bapedibupa'', remodified)

```sqf
_obj attachTo [_logic,[0,0,2]];
[_obj,[120,-78,37]] call fnc_SetPitchBankYaw; // pitch: 120, bank: -78, yaw: 37
```

```sqf
fnc_SetPitchBankYaw = {
    private ["_object", "_rotations", "_aroundX", "_aroundY", "_aroundZ", "_dirX", "_dirY",
    "_dirZ", "_upX", "_upY", "_upZ", "_dir", "_up", "_dirXTemp", "_upXTemp"];
    _object = _this select 0;
    _rotations = _this select 1;
    _aroundX = _rotations select 0;
    _aroundY = _rotations select 1;
    _aroundZ = (360 - (_rotations select 2)) - 360;
    _dirX = 0;
    _dirY = 1;
    _dirZ = 0;
    _upX = 0;
    _upY = 0;
    _upZ = 1;
    if (_aroundX != 0) then {
        _dirY = cos _aroundX;
        _dirZ = sin _aroundX;
        _upY = -sin _aroundX;
        _upZ = cos _aroundX;
    };
    if (_aroundY != 0) then {
        _dirX = _dirZ * sin _aroundY;
        _dirZ = _dirZ * cos _aroundY;
        _upX = _upZ * sin _aroundY;
        _upZ = _upZ * cos _aroundY;
    };
    if (_aroundZ != 0) then {
        _dirXTemp = _dirX;
        _dirX = (_dirXTemp* cos _aroundZ) - (_dirY * sin _aroundZ);
        _dirY = (_dirY * cos _aroundZ) + (_dirXTemp * sin _aroundZ);
        _upXTemp = _upX;
        _upX = (_upXTemp * cos _aroundZ) - (_upY * sin _aroundZ);
        _upY = (_upY * cos _aroundZ) + (_upXTemp * sin _aroundZ);
    };
    _dir = [_dirX,_dirY,_dirZ];
    _up = [_upX,_upY,_upZ];
    _object setVectorDirAndUp [_dir,_up];
};
```

<sub>Source: [BI Community Wiki — setVectorDirAndUp](https://community.bistudio.com/wiki/setVectorDirAndUp) (revision 378407).</sub>
