OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Anci on 24 Jun 2003, 09:11:37
-
How to make unit to move near other unit ?
unit1 move (getpos unit2) <--- this causes unit1 move to exactly same place where unit2 is, but how can i make unit1 move let's say 50 meters away from unit2 ?
I hope u got the idea... :)
-
Ahh.. Tricky one..
Unit1 move [(getpos unit2 select 0) + 50, getpos unit2 select 1, getpos unit2 select 2]
Does it work?
-
It works ! :D
Would u explain to me a little bit how it works ?
I don't understand what's the purpose of that select-command.
-
position object returns a 2D/3D array of the coordinates.
_pos = (getpos player)
would make: _pos =[xxx.xxxxxx,xxx.xxxxxx,xxx.xxxxxx]
x/y/z-axis coordinates
Now when refering to the whole array you can say:
object setpos (getpos player)
or:
object setpos _pos
But if you want to the value of any of the coordinates you
have to do it piece by piece for the specific element of the
array.
Let's say you want to place it 10 meters more to the left,
then you need to increase element 0 of array _pos with
the value of 10:
_newpos = [_pos select 0 + 10,_pos select 1,_pos select 2]
Now as the third element (_pos select 2) specifies the height
value, this is not really required to be used, as long as you
only want to do: 2D setpos (move object from one place to
another).
Therefore you can also say:
_newpos = [_pos select 0 + 10,_pos select 1]
P.S: don't take left/right/up/down too serious for my explanation, as i'm not sure right now if it's element 0 or
element 1, which represents the left/right axis.
Just play around a lil bit with that and you'll see.
~S~ CD
-
Thanks. This clarified things for me. :)