Home   Help Search Login Register  

Author Topic: Help (my script to set relative pos)and(worldtomodel/modeltoworld understanding)  (Read 2530 times)

0 Members and 1 Guest are viewing this topic.

Offline Charlis

  • Members
  • *
  • I'm a llama!
    • ARMABR
hi guys, I suck at scripting, but these days i'm on a big effort to understanding (as I'm on vacation from job and have plenty time to stuy it  :good:)
After 2 days cracking my head and trying to undertand how worldtomodel/modeltoworld works and get mine ok, I decide to Ask 2 things:


1º Why this does.t work:

Quote
_Unit1 = _this select 0;
_UnitRef1 = _this select 1; 
_UnitRef2 = _this select 2;

;Get in _Re the relative position in 3D of obj2 using obj1 as coordinates origin.
_RelPos = _UnitRef modeltoWorld (getPos _Unit1);
 
_Unit1 setPos(_UnitRef2 modeltoWorld _Relpos)
deleteVehicle _UnitRef1;
deleteVehicle _UnitRef2;
exit;

No error message, mothing hapens to unit1, cones are deleted.

It's suposed to get Unit1 position relavtive to a roadcone (unitRef1) and setpos Unit1 at the same position in relation to roadcone2 (unitRef2), then to erase both cones, 'cause they're just refences. Cone1 and unit1 are in one room in a hotel and Cone2 is in another room.
Actually this is a part of script i'd like to do later to ramdomize position of taken hostages, so that 1 create a scene, with hostage and keeper, and when it loads a mission, the scene is the same but each time in a random room (predefined with "cone references' for example). As I could not solve the simple, one unit change pos this way, i'm not woried with it (now).

2º- Could you please explain more detailed and with practicall examples if possible, the way those commands work?
As all this reading is being very instructing to me and I'm being abble of understand how Arma scripting  works, i'm still not capable of solve some problems people had, both here and in BI Foruns, simlilar to mine. I think I'm not understanding it very well.

Thanks.

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Hola Charlis,

In this statement:

Code: [Select]
_RelPos = _UnitRef modeltoWorld (getPos _Unit1);

The code in the parens (where you say getPos _Unit1) is not a position, but a relative position to the _UnitRef object.

So if you want _RelPos to be a position that is 1 meter to the left of _UnitRef, 2 meters in front of _UnitRef, and 4 meters above _UnitRef, your code would look like this:

Code: [Select]
_RelPos = _UnitRef modeltoWorld ([-1,2,4]);

Note that left/right and front/back are relative to the direction that _UnitRef is facing.

Hopefully that explains modelToWorld.

But in your explanation it sounds like you simply want to move a unit to where a cone is.  In that case you really don't need a relative position.  The following code would move a unit to cone's position:

Code: [Select]
unit1 setpos (getpos cone1);
However, if cone1 is on the second story of a building, or on the roof of a building, the height (z coordinate) will be zero, which will mess up the placement of unit1.  In that case you want to do this:

Code: [Select]
_pos getpos cone1;
unit1 setpos [_pos select 0, _pos select 1, 2.3];

In the above example, the 3rd coordinate is hardcoded to 2.3, which would be the exact height you want the unit.  To get the exact number you have to experiment until the unit arrives at the right height.

Hope this helps.
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Charlis

  • Members
  • *
  • I'm a llama!
    • ARMABR
Thanks Jhonyboy for replying so fast, but I think I wasn't enough clear.

So far, I know that if I just like to move unit1 from cone1 to cone2, I better not to use modeltoworld, the problem is that, later after solving this, I intend to add other units and maybe objects to the script to make something  like a scene or situation, where I have a hostage and it's keeper pointing a gun to him for example. The idea is to simply create a scene into editor, and then just move the role scene (it's set of objets and relative positions) to other room with the script.
Assume that this is the main obj of the mission (rescue hostage),  I'd like to create some random aspect to it, so any time you play the mission, when entering the building (hotel in this case) I'll have to search the building for the hostage room and not just get into exactly on the position you seen before, everytime.

When I tried:
Code: [Select]
_RelPos = _UnitRef modeltoWorld (getPos _Unit1);
I tryed to get the pos Array from unit1, relative to cone 1, to then setpos unit1 into same relative position but to cone2 this time, wich is in another room (maybe even in another floor too) so thats why I tried this after:

Code: [Select]
_RelPos = _UnitRef modeltoWorld (getPos _Unit1);
_Unit1 setPos(_UnitRef2 modeltoWorld _Relpos)

Later as I said, I intend to add unit2 (the guy who point it's gun to unit1) and move them both to other room or maybr transform this into to a kind of function where it adds variales accordingly to an array passed by the mission designer, with as many units and random positions (cones) he wants and maybe even change the direction of the set of units in the editor created "scene", but it's very far for me now, that's why I'm so worried to try to understand how exatlly i can use and handle modetoworld and worldtomodel to get and set  positions from some object to another.

I hope I made a little bit clear what is going into my mind :cool2:.
Thanks again  ;)


Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
"Note that left/right and front/back are relative to the direction that _UnitRef is facing."

Beware, this is not literally true. Model coordinates consider only the inclination of the object in the three axes, not the current movement direction as returned by vectorDir (movement direction).

For example, model coordinates [10, 0, 0] for a plane that has rolled left 90 degrees means 10m above the plane. Model coordinates [0, -10, 0] for a plane that is climbing vertically is 10m below the plane's center. If the plane is diving vertically, 10m above plane's center. If the plane is flying leveled, 10m behind plane's center.

Note that for model coordinates, the origin [0,0,0] is always the center of the object.

Offline Charlis

  • Members
  • *
  • I'm a llama!
    • ARMABR
OK Mandoble, I got it, so it's allwys "tied" with model position refence and it this values are always related to the model itself. If the model is upside down, a plane flying this wy lets say, it mean that any positive value in third element of the array [x,y,z] will get or set the model height lower than the original position, is that it?
I'll pay attention to that when necessary but  by now, it's still not clear to me how use these comands to get what I'm trying to, and also don't know why my scripting is not working (even with no error message).
Any more help, on how can I use them to get and set the relative pos from one to other obj is very, very, very welcome.

Thanks guys!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Code: [Select]
_Unit1 = _this select 0;
_UnitRef1 = _this select 1;
_UnitRef2 = _this select 2;
_Unit1 setPos (_UnitRef2 modeltoWorld [0,0,0]);
deleteVehicle _UnitRef1;
deleteVehicle _UnitRef2;
exit;

SetPos uses world coordinates, while modelToWorld requires model coordinates. [0,0,0] in the reference object points to its center.