OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: T.S.C.Plage on 20 Aug 2002, 23:51:30

Title: setpos distance...
Post by: T.S.C.Plage on 20 Aug 2002, 23:51:30
This question was answered already in the old forum and I'm ashamed that I haven't copied the answer!  :-[

I want to place a unit/object at a specific distance from the middle of an other object or the position of an unit.

Let's say 20 meters to my 9 o'clock position for example.

It has to be something with "setpos getpos" and "distance" but I can't get the s**t together.  :(

Thanks
Plage

Title: Re:setpos distance...
Post by: LCD on 20 Aug 2002, 23:56:30
EDIT : no more double post  :o

LCD OUT
Title: Re:setpos distance...
Post by: T.S.C.Plage on 20 Aug 2002, 23:59:39
Realy big OOOOOPS!!!  ??? ??? ??? :-[

Puuuuh! God bless the delete button!!! ;D
And thanks for writing in one not both! 8)
Title: Re:setpos distance...
Post by: dismas on 21 Aug 2002, 00:50:27
I am writing this script on the fly so don't blame me if it doesn't work. ;)
And my example will use 9 o'clock 20m distant.
sol1 will be the soldier in question.

; blalalalalal, I wrote this - dismas
_possol1 = getPos sol1
_dirsol1 = getDir sol1

; 9 o'clock is 270 degree offset from direction player is facing
_dirsol1 = _dirsol1 + 270
; I'm pretty sure that OFP corrects for values greater than 360, but some correction lines may need to be added

; new position, not going to worry about our third dimension
_newx1 = (_possol1 select 0) + (20 * (sin _dirsol1))
_newy1 = (_possol1 select 1) + (20 * (cos _dirsol1))

_newjeep = "jeep" createVehicle [_newx1, _newy1, _possol1 select 2]

exit

edit: edit:
heheh, made a small mistake +/-, and another mistake with 1/0. :)
Title: Re:setpos distance...
Post by: T.S.C.Plage on 21 Aug 2002, 00:58:02
Thanks,

maybe that's one solution but a lil' difficult! I'll try if I can work with it but I'm sure there's an other (shorter) solution.

That's why I'm not "closing" this topic.

Greetz
Plage
Title: Re:setpos distance...
Post by: dismas on 21 Aug 2002, 01:13:08
I thought it was fairly simple.
I didn't make it as nice as some people who put a lot of effort into their scripts to make them widely used.

Change the value 20 to whatever distance you want (distance from what to what)

the value 270 is equivalent to 9 o'clock from where the object is facing.  Take or imagine a compass and transpose a clock over it to get a conversion.

I added a line where it makes a jeep 20m distant from the soldiers 9 o'clock.  which is easily changable to whatever you want.. an explosion, tank, ai soldiers, even a move command.

I suppose I could have put more effort into it, but I'm lazy. ;)

Sorry it wasn't more clear.
Title: Re:setpos distance...
Post by: T.S.C.Plage on 21 Aug 2002, 01:20:33
OK, I'll check it in a few seconds...
Title: Re:setpos distance...
Post by: Sui on 21 Aug 2002, 03:04:37
...or you can do exactly the same thing without using a script:

object setpos [(getpos unit select 0) + (sin (getdir unit - 90) * 20), (getpos unit select 1) + (cos (getdir unit - 90) * 20), 0]

Breaking it down to explain it...

(getpos unit select 0)

gets the x co-ord of unit

... + (sin (getdir unit - 90) * 20)

minus's a value that depends on the direction unit is facing. The - 90 means the position will be 90 degrees to the left of where the unit is facing. The * 20 means the distance will be 20m away.

... (getpos unit select 1) + (cos (getdir unit - 90) * 20)

this is exactly the same as the x co-ord line, apart from the underlined differences. These are necessary due to the y co-ord being perpendicular to the x co-ord

While that may look like a long complicated line, it's actually not too bad and reasonably easy to use once you understand it.
I suggest you have a play around with it, as it has great potential for use in many situations ;)
Title: Re:setpos distance...
Post by: T.S.C.Plage on 21 Aug 2002, 18:09:13
Thanks all!

I've got a solution. :D

A pleased Plage