Jump to content
Sign in to follow this  
konyo

Can someone explain the attachto command to me?

Recommended Posts

Can some explain the attachto command?

Ive search around the forums and found nothing?

At the moment im using the attachto command like this :

attachto [lhdcarrier[7,7,4]] And when i press enter it just says missing ';' all the time?

Why its doing this? Can someone explain better how i get the attachto command to work?

Share this post


Link to post
Share on other sites

Because you're missing the name at the start. It should be something like:

this attachTo [lhdcarrier[7,7,4]]

Share this post


Link to post
Share on other sites
Because you're missing the name at the start. It should be something like:

this attachTo [lhdcarrier[7,7,4]]

Ohhh okay that explains. Thankyou :)

Edit : Now its saying im missing a ']'

Edited by konyo

Share this post


Link to post
Share on other sites
Hi,

take a look at the BIKI reference... http://community.bistudio.com/wiki/attachTo

You need to seperate the two parameters by a comma...

player attachto [lhdcarrier,[7,7,4]]

Hope that does the trick.

Cheers

Okay thanks, ill give that a shot in a few :)

Edit : Just tryed attaching, no errors with script :) yay. But when i mess around with the numbers for height and stuff, it just stays at the bottom of the sea?

Edited by konyo

Share this post


Link to post
Share on other sites

Sorry for double post, but i now got it working. But its only facing one way? And when i set the numbers for it to face, it still faces the way it automatically dose when you use the attachto command? How can i get it facing another way?

Share this post


Link to post
Share on other sites

Set the desired orientation after you attach it.

Share this post


Link to post
Share on other sites
Set the desired orientation after you attach it.

What do you mean? :confused:

Ive attached it to the lhd, and changed the orientation, but it still dose nothing? Or do you have to leave it at zero, then change it up?

Share this post


Link to post
Share on other sites

As I recall, the one time I needed to change the orientation of an attached object, I just used General Barron's script after attaching it to rotate it 90-degrees on its x-axis so it was facing down instead of north. I do remember the object I attached acting a little strangely when I rotated it, but I think it's the fact that it was attached to an object that was attached to another object more than the rotation that caused it.

Now, if you only need rotation on the Z-axis (i.e. rotate it left and right, like yawing in car), then you can just use 'setDir'.

Here's the script:

/************************************************************
Set Pitch and Bank
By General Barron ([email=aw_barron@hotmail.com]aw_barron@hotmail.com[/email]) and vektorboson

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.
************************************************************/

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

_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);


//----------------------------
//function to rotate a 2d vector around the origin
//----------------------------

_rotate =
{
private ["_v","_d","_x","_y"];

//extract parameters
_v = +(_this select 0); //we don't want to modify the originally passed vector
_d = _this select 1;

//extract old x/y values
_x = _v select 0;
_y = _v select 1;

//if vector is 3d, we don't want to mess up the last element
_v set [0, (cos _d)*_x - (sin _d)*_y];
_v set [1, (sin _d)*_x + (cos _d)*_y];

//return new vector
_v
};


//----------------------------
//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 X & Y around the origin according to object's yaw (direction)
_vdir = [_vdir, _yaw] call _rotate;


//----------------------------
//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 Y & Z elements according to pitch
_vup = [_vup select 0] + ([[_vup select 1, _vup select 2], _pitch] call _rotate);

//rotate X & Y around origin according to yaw
_vup =  [_vup,  _yaw] call _rotate;


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

_obj setVectorDirAndUp [_vdir, _vup];

then add

setPitchBank = compile preprocessfile "scripts\setPitchbank.sqf";

to your init script and call the function like so:

[object, pitch, bank] call setPitchBank;

Edited by MH6

Share this post


Link to post
Share on other sites

Or just follow the attachto with SetDir command?

This SetDir 180; (to make it face ...180).

Alex

Share this post


Link to post
Share on other sites
Or just follow the attachto with SetDir command?

This SetDir 180; (to make it face ...180).

Alex

Yes, I was putting that in as you typed it.

Share this post


Link to post
Share on other sites
could you attach a camera to something like the tailboom on the SH-60?

Yep. Something like this would do what you want. Might need to change the variables a bit.

       _bcam = "camera" createVehicleLocal getPos(_chopper);
       _bcam cameraEffect ["INTERNAL", "BACK"];
       _bcam camSetTarget _chopper;
       _bcam camCommit 0;
       _bcam attachTo [_chopper,[0,-10,0]];

Share this post


Link to post
Share on other sites
Or just follow the attachto with SetDir command?

This SetDir 180; (to make it face ...180).

Alex

Okay ill give that one ago, as it seem more simple lol :)

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  

×