Jump to content
Sign in to follow this  
chris330

SetVectorDirandUp Usage Solved

Recommended Posts

Hi!

Not sure if this is already common knowledge but I've worked out how to use the setvectordirandup command to set a unit (aircraft at least) to any pitch and/or bank you wish.

The command takes two arrays:

[x,y,z],[x,y,z]

The command reference lists the variable runs as different but from my own testing the above criteria is correct.

The first array sets the axis along which the aircraft will point. It cannot take 3 zero values as far as I know, this causes the command not to execute or hang.

So for example if you wanted to point your aircraft at dead West you would enter [-1,0,0] in the first array. The x co-ordinate is read positve facing east (right) and negative west (left).

The second array is used to set the aircraft's rotation about the axis specified in the first array and it too cannot take a [0,0,0] input.

This second array also has some odd workings. The x and y part are not what you think. The x value simply represents roll in the right handed direction local to the vehicle's frame (i.e. not world coordinates) and the y value represents the vehicles roll in the left handed direction. You can basically just leave the y column blank and work with negative values of x value when you want the aircraft to roll left. Also they sum together arithmetically. A value of:

[1,0.5,0] in the second array gives the same result as:

[0.5,0,0] :)

So for example if you wanted to point your vehicle dead West and have it at an angle of 45 degrees bank right in respect of that axis you would input something like:

_aircraft = setvectordirandup [[-1,0,0],[1,0,1]];

And that will do it. If you wanted to point it dead North East and have it zero degree bank but pitched 45 degrees down you would do the following:

_aircraft = setvectordirandup [[0.5,0.5,0.707],[0,0,1]];

Note the '1' in the second vector just means 'no rotation' about the axis or also translated as 'upvector just point straight up' i.e. do nothing.

---------- Post added at 06:36 PM ---------- Previous post was at 06:12 PM ----------

This actually fits in well with what I've read about up to date Physics engines. They use a thing called a Quaternion which holds an axis with three components to represent that axis - and a rotation value for the rotation about that axis. Seems this setvectordirandup command is very closely related. It means ocne you've learned to use this properly you don't need to use setdir and then setvectorup to set pitch. You can set direction, pitch and bank all in one go.

---------- Post added at 06:48 PM ---------- Previous post was at 06:36 PM ----------

I'm off out now for a few hours but I'll do some more testing later to make sure these findings are correct. I've already done alot of testing to make sure the findings are solid before posting but as anyone who's been around even just a little bit will know, it only takes one small observation and suddeny everything's on its head!

God Bless :)

Share this post


Link to post
Share on other sites

I did some testing myself and found that there is a pitch function in Arma2 that makes some things a little easier, maybe it's of some use.

http://www.sendspace.com/file/lawc53

I've used vector and pitch combined with explosions to in other missions to give a better effect of a bomb.

I still have problems getting my head around vectoring as at a certain point it changes it's direction face.

I can make the plane do a roll but not a full loop. I know there are other ways of doing I just can't do it with pitch.

Share this post


Link to post
Share on other sites

I just noticed I didn't include the FN code so you could see what it actually does.

[] call BIS_fnc_hscriptName "Functions\objects\fn_.sqf";
/************************************************************
Set Pitch and Bank
By Andrew Barron

Parameters: [object, pitch, bank]
Returns: nothing

Rotates an object, giving it the specified pitch and bank,
in degrees.

Pitch is 0 when the object is level; 90 when pointing straight
up; and -90 when pointing straight down.

Bank is 0 when level; 90 when the object is rolled to the right,
-90 when rolled to the left, and 180 when rolled upside down.

Note that the object's yaw can be set with the setdir command,
which should be issued before using this function, if required.

The pitch/bank can be leveled out (set to 0) by using the
setdir command.

Example: [player, 45, -45] call BIS_fnc_setPitchBank
************************************************************/

//extract parameters
private ["_obj","_pitch","_bank","_yaw","_vdir","_vup","_sign"];

_obj = _this select 0;
_pitch = _this select 1;
_bank = _this select 2;

//find the yaw (direction) of the object
//map compass directions go CW, while coordinate (vector) directions go CCW, so we need to flip this
//if we don't flip this, the object will face backwards
_yaw = 360-(getdir _obj);


//----------------------------
//find vector dir (pitch)
//----------------------------

//find sign of pitch
_sign = [1,-1] select (_pitch < 0);

//cut off numbers above 180
while {abs _pitch > 180} do {_pitch = _sign*(abs _pitch - 180)};

//we can't use pitch that is exactly equal to 90, because then the engine doesn't know what 2d compass direction the object is facing
if(abs _pitch == 90) then {_pitch = _sign*(89.9)};

//we can't pitch beyond 90 degrees without changing the facing of our object
//(pitching beyond 90 degrees means that the object's eyes will point in the 2d compass direction that its back used to point)
if(abs _pitch > 90) then
{
//we are rolling upside down; flip our direction (yaw)
_obj setdir (getdir _obj)-180;
_yaw = 360-(getdir _obj);

//use bank to flip upside down
_bank = _bank + 180;

//and adjust our original pitch
_pitch = (180 - abs _pitch)*_sign;
};

//find appropriate vdir according to our pitch, as if we were facing north
_vdir = [0, cos _pitch, sin _pitch];

//then rotate around the origin according to object's yaw (direction)
_vdir = [_vdir, _yaw] call BIS_fnc_rotateVector2D;


//----------------------------
//find vector up (bank)
//----------------------------

//find sign of bank
_sign = [1,-1] select (_bank < 0);

//cut off numbers above 360
while {abs _bank > 360} do {_bank = _sign*(abs _bank - 360)};

//reflect numbers above 180
if(abs _bank > 180) then {_sign = -1*_sign; _bank = (360-_bank)*_sign};

//find appropriate vup according to our bank, as if we were facing north
_vup  = [sin _bank, 0, cos _bank];

//rotate around origin
_vup =  [_vup,  _yaw] call BIS_fnc_rotateVector2D;


//----------------------------
//apply the vectors
//----------------------------

_obj setVectorDirAndUp [_vdir, _vup];

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I still probably won't be able to work it out :D

Thanks for posting that that's great! I wish everyone was helpful like you. If I can work out what's happening in my thread about update times I might make use of this instead of that function I wrote to setpitch.

If you want F2k Sel I'll send you that mission I wrote where I did it. I could set vehicles upside down with it without any problems, although that might be different from gradually increasing their pitch like in a loop scenario.

Share this post


Link to post
Share on other sites

A loop isn't really needed and can be done other ways, I just wanted it to give me a little more control of the aircraft at certain times and this it does quite well.

If you do have an easy way of flipping a vehicle upside down it would be useful.

Share this post


Link to post
Share on other sites

Hi pal try this one. Use pretty much any values for the first two entries in the first array but leave the third entry in it blank. Used like this the first array controls only bearing.

Must be of form - [x,x,0].

The second array must only contain [0,0,-1].

This will flip your aircraft upside down. The script is run to hold it at that position. I hope that helps ;)

Your Mission

Share this post


Link to post
Share on other sites

Hi,

The value specified as setvector can be treated by trigonometric-functions calculation.

_dir = 60;

_angle = 45;

_pitch = 30;

_vecdx = sin(_dir) * cos(_angle);

_vecdy = cos(_dir) * cos(_angle);

_vecdz = sin(_angle);

_vecux = cos(_dir) * cos(_angle) * sin(_pitch);

_vecuy = sin(_dir) * cos(_angle) * sin(_pitch);

_vecuz = cos(_angle) * cos(_pitch);

object setVectorDirAndUp [ [_vecdx,_vecdy,_vecdz], [_vecux,_vecuy,_vecuz] ];

Although I do not grasp in detail so well that it can explain, the setvector command determines the posture of an object by specifying xyz vector for the angle of two space axes which goes direct.

Pleased if it is help :)

  • Like 1

Share this post


Link to post
Share on other sites

I'll take a look at that later it looks helpful thanks.

Share this post


Link to post
Share on other sites

I drop a vehicle from a c130 and attach it to a "ParachuteBigWest", but most of the time the parachute tilt sideways and result in vehicle and chute to land / or __

I assume its the force of the wind from the c130 affecting it, or somehow the balance of the chute is disturbed due to the vehicle being attached to it at the bottom.

Vehicle is spawned with full crew prior to drop and moved to c130 pos and then atached to chute spawned at rear of c130, so i dont think i can use the function by BIS to cargodrop or what it is called.

Can anyone help me with using setVectorDirAndUp to adjust the parachute with the vehicle attached in its flight down to the ground so it will land relatively vertical and not on its side?

basically im looking for a script snippet to adjust an object (the parachute) in steps (so it seems not sudden but real...ish...) to a vertical state on its way down towards ground and same time keepig its original direction.

Any help will be much appreciated.

Edit: Even better make the chute open up pointing directly out of the rear of the c130 (top of chute is pointing same way as the aas of the c130) and then catch wind and correct itself to a vertical position.

Edited by Demonized

Share this post


Link to post
Share on other sites

This will rotate an object vertically about 90 degrees, you may need to use the getPitchBank function and take that away from the amount of rotation otherwise it will over compensate. I haven't tried it with chutes but with planes and other objects it will work.

The problem I can never get my head around is direction, ie chute setvectorup [-1,0,0.001] will open a chute horizontally but only in one direction. Even using setdir which makes sense as the object is on it's side.

// nul=[planename] execvm"pitchup.sqf" ;

_plane1 = _this select 0;

_pitchbank = _plane1 call BIS_fnc_getPitchBank;
_pitch     = _pitchbank select 0;
_bank      = _pitchbank select 1;

// hint format ["%1",_pitchbank];

for [{_p = _pitch},{_p < _pitch+90},{_p = _p + .5}] do
{
sleep 0.009;
[_plane1,_p, _bank] call BIS_fnc_setPitchBank;
};

Edited by F2k Sel

Share this post


Link to post
Share on other sites

cheers F2k Sel

Edit: this worked nicely rotating the chute with the attached vehicle 90 degrees to a horisontal position, now to find out how to rotate based on direction.

Edit2: Solution: Place code in initline of object:

ang=0;
ptc=0;
//dr=(direction this);
dr=(direction plane);
parachute setVectorDirAndUp [ [(sin(dr) * cos(ang)),(cos(dr) * cos(ang)),sin(ang)],[(cos(dr) * cos(ang) * sin(ptc)),(sin(dr) * cos(ang) * sin(ptc)),(cos(ang) * cos(ptc))]];

ang= angle of object.+/-

ptc= pitch of object.+/-

dr= direction of object. ("direction this" puts in objects current heading in the editor.)

Start code with "This setdir 0;" to set the yaw

this worked nicely for having parachute lay down 90 degrees out of the ass of the plane, now i only need to do it in steps to adjust it back to vertical position.

NOTE: (direction this was direction of my plane) And ang was my 90 degrees vertical position.

---------- Post added at 11:34 PM ---------- Previous post was at 10:51 PM ----------

solved above in spoiler, got info from a post in 3PARA _GU web site, a very extensive explanation on different usages of this, this was the part that was relevant for my question.

Explanation of the cos and sin and how it really works is beyond my math skills, im so glad there are people that have these skills so i dont need to :)

Edited by Demonized

Share this post


Link to post
Share on other sites

Yea I did nearly get it working using the maths on the other page but it wouldn't work on the chute for some reason. For a box it would work fine and match to the direction of the plane.

I must admit I don't really know what it's doing as maths and trig won't stick in my head for more than a second.

By the way you wouldn't happen to have any dust scripts that could be used when an object hits the ground. Small, Medium and Large would be quite useful.

Share this post


Link to post
Share on other sites

I havent looked into particle creation as much but i asume its similar to the sandstorm just miniature you mean, for a short while.

Would be a nice addition to the paradrop yes, if i come across something ill let you know.

Share this post


Link to post
Share on other sites

That's what I was thinking, Another thing I like to do is rotate the objects in different directions and speed as they drop I think it looks so much better than everything landing facing the same way.

Share this post


Link to post
Share on other sites
Another thing I like to do is rotate the objects in different directions and speed as they drop I think it looks so much better than everything landing facing the same way.

sleep timers and maybe amount of spin probably needs adjusting but something like this:

_object = _this select 0;
_dirSpin = floor(random 2);
// choose left or right spin based on random above.
if (_dirSpin == 0) then {_dirSpin = (-0.1 + (random -0.5))} else {_dirSpin = (0.1 + (random 0.5))};
// while object is 1 above ground continue spins.
while {(getPos _object select 2) > 1} do {
_currentDir = (getDir _object);  // get curent direction of object.
_object setDir (_currentDir + _dirSpin);  // adjust spin left or right.
sleep 0.001
};

Edited by Demonized

Share this post


Link to post
Share on other sites

@Demonized

I'm looking for a script like one directly above, but to bank or roll a airplane. i.e. it lost a wing and is spinning out of control, rotating around only its long nose-to-tail axis.

The script would ignore any pitch or yaw changes (let them happen as "natural"). The plane would free fall, but simply roll.

Possible?

I'm guessing it has to use setVectorDirAndUp, but probably has to read all current parameters of an object before biasing the "up" vector, then loop again ..... ?

3D maths is not a skill I have ! ;)

Edited by [APS]Gnat

Share this post


Link to post
Share on other sites
Gnat;2013636']@Demonized

I'm looking for a script like one directly above' date=' but to bank or roll a airplane. i.e. it lost a wing and is spinning out of control, rotating around only its long nose-to-tail axis.

The script would ignore any pitch or yaw changes (let them happen as "natural"). The plane would free fall, but simply roll.

Possible?

I'm guessing it has to use setVectorDirAndUp, but probably has to read all current parameters of an object before biasing the "up" vector, then loop again ..... ?

3D maths is not a skill I have ! ;)[/quote']

SetVectorDirAndUp is a bit beyond me, I can get it to do some stuff but it's not easy.

You could try using the pitch/bank function.

place this in a waypoint or in a trigger when it gets x amount of damage.

null=[air1,360,0.01] execvm "roll.sqf" ;

That will roll it once just increase the larger number to increase the number of rolls.

// nul=[planename,degrees,transitionspeed] execvm "roll.sqf" ;
// null=[air1,360,0.01] execvm "roll.sqf" ;
// degrees 360 would = 1 roll, 720 = two rolls, pick a large number for multiple rolls.
// transition = the speed of the roll, the smaller the number the faster the roll 

_plane = _this select 0;

_pitchbank = _plane call BIS_fnc_getPitchBank;
_pitch     = _pitchbank select 0;
_bank      = _pitchbank select 1;
_deg       = _this select 1;
_transpeed = _this select 2;

_down = 0.5; // amount used to force the plane down.

// input new bank angle

for [{_p = _bank},{_p < _bank + _deg},{_p = _p + 1}] do {
sleep _transpeed;
  [_plane,_pitch, _p] call BIS_fnc_setPitchBank;
     if (getpos _plane select 2 < 20) exitWith {};// height at which roll should stop
 _pitch  = _pitch  -0.05;// This will force it down a little quicker  
};

Share this post


Link to post
Share on other sites

Very amiss of me to not say thanks F2kSel.

Thanks!

Skeleton from above was used to make a plane which has lost a wing to spiral out of control, into the ground. Works well.

To be seen in I44 eventually.

Don't suppose anyone knows how to read / effect yaw?

get/setDir doesn't take into account the actual vector of the aircraft. And won't work for example if the unit is nose-down or nose-up.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×