Home   Help Search Login Register  

Author Topic: setpos distance...  (Read 3069 times)

0 Members and 1 Guest are viewing this topic.

T.S.C.Plage

  • Guest
setpos distance...
« 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


Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:setpos distance...
« Reply #1 on: 20 Aug 2002, 23:56:30 »
EDIT : no more double post  :o

LCD OUT
« Last Edit: 21 Aug 2002, 00:05:06 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

T.S.C.Plage

  • Guest
Re:setpos distance...
« Reply #2 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)
« Last Edit: 21 Aug 2002, 00:02:24 by T.S.C.Plage »

dismas

  • Guest
Re:setpos distance...
« Reply #3 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. :)
« Last Edit: 21 Aug 2002, 00:52:55 by dismas »

T.S.C.Plage

  • Guest
Re:setpos distance...
« Reply #4 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

dismas

  • Guest
Re:setpos distance...
« Reply #5 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.

T.S.C.Plage

  • Guest
Re:setpos distance...
« Reply #6 on: 21 Aug 2002, 01:20:33 »
OK, I'll check it in a few seconds...

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:setpos distance...
« Reply #7 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 ;)
« Last Edit: 21 Aug 2002, 03:06:38 by Sui »

T.S.C.Plage

  • Guest
Re:setpos distance...
« Reply #8 on: 21 Aug 2002, 18:09:13 »
Thanks all!

I've got a solution. :D

A pleased Plage