Jump to content
Sign in to follow this  
nuxil

how to tilt a object

Recommended Posts

hi forum.. i would like to get some help..

im trying to make a missile move to a target.

but i cant get the missile to tilt up/down.

i dont got the script infront of me since im at work.. but it looks simelar to this.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_me = _this select 0;

_targer = _this select 1;

_Mx = getpos _me select 0;

_My = getpos _me select 1;

_Mz = getpos _me select 2;

_dirme = getdir _me;

_missile = "M_Ch29_AT" createvehicle [0,0,0];

_missile setpos [_Mx,_My,_Mz +10];

_missile setdir _dirme;

while {(alive _missile)} do

{

_MiX = getpos _missile select 0;

_Miy = getpos _missile select 1;

_Miz = getpos _missile select 2;

_Tx = getpos _target select 0;

_Ty = getpos _target select 1;

_Tz = getpos _target select 2;

_dirX = (_Tx - _Mix);

_dirY = (_Ty - _Miy);

_dirZ = (_Tz - _Miz);

_dir=[_dirX,_dirY,_dirZ];

_missile setvectordir _dir;

};

the missile moves correct right/left. but up/down it dosent move fine at all..

any ideas?

Share this post


Link to post
Share on other sites

that simple ?

I thought setvectorup only worked with +1 / -1 for the 3 axis..

exs: [1,0,-1];

could anyone point me to a good vectorup/dir guide!

Share this post


Link to post
Share on other sites

Thanks UNN.

looks amazing, but i dont understand crap of that.

[_OBJECT,[_Ox,_Oy,_Oz]] <-- = huh.gif?

so lets say that _OBJECT is my missile.

is _Ox,_Oy,_Oz its pos? in that case why use extra parameters. why not just get the pos from within the script!

Share this post


Link to post
Share on other sites

hi nux,

I think [_Ox,_Oy,_Oz] is the vector of the direction you want to set the object.

Master85

Share this post


Link to post
Share on other sites

setVectorUp is very confusing, there's almost no information about it whatsoever. I mean, are those co-ords relative or absolute? Are they even co-ords or are they angles? If they're angles are they degrees or what? No info at all.

Share this post


Link to post
Share on other sites

DMarkwick yeah. setvectorup is verry confusing..

and setvectordir i dont understand the point of.

setdir does exactly the same. since the z agrument for setvectorup dosent seem to work well. bug in setvectordir?

form what i understand vectorup sets the bank "lef/right"

while vectordir sets the direction left/right. not up/down vectors, but no 100% sure here.

Master85 that makes me more confused..

if you know the vectors "[ox,oy,oz]" you can just do _object setvectorup [ox,oy,oz];

someone should update the wiki or atleast make a good guide for thouse two commands. the info on the wiki sucks.

Share this post


Link to post
Share on other sites

I didn't talked about the command "setvectorup" or "setvectordir", I talked about the script (link posted by UNN) whose startup-parameter you had posted.

Quote[/b] ][_OBJECT,[_Ox,_Oy,_Oz]] <-- = huh.gif?

Share this post


Link to post
Share on other sites
I didn't talked about the command "setvectorup" or "setvectordir", I talked about the script (link posted by UNN) whose startup-parameter you had posted.
Quote[/b] ][_OBJECT,[_Ox,_Oy,_Oz]] <-- = huh.gif?

I think the confusion is that, apparently, exactly the same parameters need to be passed to setDir3d as setVectorUp. The only difference I might see is that one sets the direction the object points, while the other sets the direction of "up" for that object. But that doesn't explain all the complex code in the script. Obviously the script does something non-obvious.

Also, I reckon a vector is a 3D direction, right? So for a 3D direction, I only need 2 parameters. Compass direction and up/down direction. I might have need for a distance parameter, if you want to include distance as vector info (which some do).

The only thing I can think of is that the 3 parameters refer to a co-ordinate that the object will then "point" toward.

Share this post


Link to post
Share on other sites

mr.Flea's function takes degrees as it's parameter. I'm only saying that cause he uses them with Sin and Cos:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_a = _this select 1;

_t_sin = sin -(_a select OX);

_t_cos = cos -(_a select OX);

Quote[/b] ]The only difference I might see is that one sets the direction the object points, while the other sets the direction of "up" for that object. But that doesn't explain all the complex code in the script. Obviously the script does something non-obvious.

Here's my attempt to explain what’s going on, but I'm a beginner so it could be wrong.

You pass into mr.Flea's function the angle you want in degrees; direction, pitch and bank e.t.c The object itself is held in memory and always points to [0,0,0]. When the game wants to draw the object, it copies the objects cords that reside in memory. Then transforms (or rotates) the object to point in the desired direction with the defined pitch and bank. That’s why the parameters you pass are absolute, each time it recalculates from the object held in memory, thats always pointing towards [0,0,0].

SetVectorDir does the same thing as SetDir. Only it takes normalised vectors, which makes it easier when you want to use a matrix like mr.Flea did. You use SetVectorDir and SetVectorUp together, to perform the correct; direction, pitch and bank rotations.

Theres a basic example here, showing a breakdown for each of the rotations.

Share this post


Link to post
Share on other sites

Thanks UNN for taking your time and explain it to me/us smile_o.gif

btw in mr.flea's script. howcome he uses VY and VZ before they are defined?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#define ROL [\

M1(1,0) * VY + M1(2,0) * VZ,\

M1(1,1) * VY + M1(2,1) * VZ,\

M1(1,2) * VY + M1(2,2) * VZ\

]

#define VY 1

#define VZ 0

Share this post


Link to post
Share on other sites

It's easiest to think of the vector directions as a point on a unit sphere with its origin at the object you're concerned about. VectorDir is the direction the front of the object is pointing, VectorUp is the direction the top of the object is pointing. You need both to define an object in roll, pitch, and yaw.

If I'm remembering correctly, X is east, Y is north, and Z is up. Northeast at zero elevation is, for example, [sqrt(2)/2, sqrt(2)/2, 0].

For vehicles I believe X is left, Y is up, and Z is forward.

I just use this code I wrote once before and I've never had to worry about it again. The zero is a bit kooky, though. Azimuth is zeroed to south, and positive to the counter-clockwise direction. Elevation is zeroed to down, and only positive. I'm too lazy to try to change it, since I can just add 180 if need be.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_dir = vectorDir _xxx;

_dirx = _dir select 0;

_diry = _dir select 1;

_dirz = _dir select 2;

_azimuth = _dirx atan2 _diry;

_elevation = sqrt(_diry*_diry + _dirx*_dirx) atan2 (-_dirz);

_dir = [sin(_elevation) * sin(_azimuth), sin(_elevation) * cos(_azimuth), - cos(_elevation)]; // same as before

Or, I guess, you could use mr.Flea's script. I haven't looked at it.

Share this post


Link to post
Share on other sites

@NonWonderDog

That code will come in handy. But what would be really handy is the code for returning the roll of the vehicle? In other words, the angle of rotation around the Z axis, in degrees.

Cheers

Share this post


Link to post
Share on other sites
Quote[/b] ]btw in mr.flea's script. howcome he uses VY and VZ before they are  defined?

MrFlea's function after it's been loaded into memory with PreProcessFile looks like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private["_x","_y","_z","_a","_t_sin","_t_cos","_dir","_up"];

_a = _this select 1;

_t_sin = sin -(_a select 0);

_t_cos = cos -(_a select 0);

_x =[[_t_cos,_t_sin,0],[-_t_sin,_t_cos,0],[0,0,1]];

_t_sin = sin (_a select 1);

_t_cos = cos (_a select 1);

_y =[[1,0,0],[0,_t_cos,_t_sin],[0,-_t_sin,_t_cos]];

_t_sin = sin (_a select 2);

_t_cos = cos (_a select 2);

_z =[[_t_cos,0,-_t_sin],[0,1,0],[_t_sin,0,_t_cos]];

_a = [[((_y select 0) select 0) * ((_x select 0) select 0)+ ((_y select 0) select 1)* ((_x select 1) select 0)+ ((_y select 0) select 2)* ((_x select 2) select 0),

      ((_y select 0) select 0) * ((_x select 0) select 1)+ ((_y select 0) select 1)* ((_x select 1) select 1)+ ((_y select 0) select 2)* ((_x select 2) select 1),

      ((_y select 0) select 0) * ((_x select 0) select 2)+ ((_y select 0) select 1)* ((_x select 1) select 2)+ ((_y select 0) select 2)* ((_x select 2) select 2)],

     [((_y select 1) select 0) * ((_x select 0) select 0)+ ((_y select 1) select 1)* ((_x select 1) select 0)+ ((_y select 1) select 2)* ((_x select 2) select 0),

      ((_y select 1) select 0) * ((_x select 0) select 1)+ ((_y select 1) select 1)* ((_x select 1) select 1)+ ((_y select 1) select 2)* ((_x select 2) select 1),

      ((_y select 1) select 0) * ((_x select 0) select 2)+ ((_y select 1) select 1)* ((_x select 1) select 2)+ ((_y select 1) select 2)* ((_x select 2) select 2)],

     [((_y select 2) select 0) * ((_x select 0) select 0)+ ((_y select 2) select 1)* ((_x select 1) select 0)+ ((_y select 2) select 2)* ((_x select 2) select 0),

      ((_y select 2) select 0) * ((_x select 0) select 1)+ ((_y select 2) select 1)* ((_x select 1) select 1)+ ((_y select 2) select 2)* ((_x select 2) select 1),

      ((_y select 2) select 0) * ((_x select 0) select 2)+ ((_y select 2) select 1)* ((_x select 1) select 2)+ ((_y select 2) select 2)* ((_x select 2) select 2)]];

_a = [[((_z select 0) select 0) * ((_a select 0) select 0)+ ((_z select 0) select 1)* ((_a select 1) select 0)+ ((_z select 0) select 2)* ((_a select 2) select 0),

      ((_z select 0) select 0) * ((_a select 0) select 1)+ ((_z select 0) select 1)* ((_a select 1) select 1)+ ((_z select 0) select 2)* ((_a select 2) select 1),

      ((_z select 0) select 0) * ((_a select 0) select 2)+ ((_z select 0) select 1)* ((_a select 1) select 2)+ ((_z select 0) select 2)* ((_a select 2) select 2)],

     [((_z select 1) select 0) * ((_a select 0) select 0)+ ((_z select 1) select 1)* ((_a select 1) select 0)+ ((_z select 1) select 2)* ((_a select 2) select 0),

      ((_z select 1) select 0) * ((_a select 0) select 1)+ ((_z select 1) select 1)* ((_a select 1) select 1)+ ((_z select 1) select 2)* ((_a select 2) select 1),

      ((_z select 1) select 0) * ((_a select 0) select 2)+ ((_z select 1) select 1)* ((_a select 1) select 2)+ ((_z select 1) select 2)* ((_a select 2) select 2)],

     [((_z select 2) select 0) * ((_a select 0) select 0)+ ((_z select 2) select 1)* ((_a select 1) select 0)+ ((_z select 2) select 2)* ((_a select 2) select 0),

      ((_z select 2) select 0) * ((_a select 0) select 1)+ ((_z select 2) select 1)* ((_a select 1) select 1)+ ((_z select 2) select 2)* ((_a select 2) select 1),

      ((_z select 2) select 0) * ((_a select 0) select 2)+ ((_z select 2) select 1)* ((_a select 1) select 2)+ ((_z select 2) select 2)* ((_a select 2) select 2)]];

_dir = [((_a select 1) select 0) * 1 + ((_a select 2) select 0) * 0,((_a select 1) select 1) * 1 + ((_a select 2) select 1) * 0,((_a select 1) select 2) * 1 + ((_a select 2) select 2) * 0];

_up = [((_a select 1) select 0) * 0 + ((_a select 2) select 0) * 1,((_a select 1) select 1) * 0 + ((_a select 2) select 1) * 1,((_a select 1) select 2) * 0 + ((_a select 2) select 2) * 1];

(_this select 0) SetVectorDir _dir;

(_this select 0) SetVectorUp _up;

[_up,_dir]

It's just a way of reducing the mount of typing in a function or script. He could have written it like it is above, only it would be harder to maintain and more prone to errors.

So when he defines:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#define M1(X,Y) ((_a select X) select Y)

That just means you replace any occurrence of M1(1,0) With:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">((_a select 1) select 0)

He's ok defining VY and VZ where he does, because it not evaluated until this line:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dir = ROL;

Then any occurrence of VY and VX in ROL are replaced with the values 1 and 0.

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  

×