Home   Help Search Login Register  

Author Topic: Keeping position in a Setpos  (Read 1273 times)

0 Members and 1 Guest are viewing this topic.

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Keeping position in a Setpos
« on: 31 Aug 2002, 20:30:34 »
Ok peoples.  I have a looped setpos.  The loop keeps one object relative to another.

Unfortunately if the independant object turns around then the dependant object does not move accordingly.  Unfortunately if I do a setpos with a +10 on the Y axis it moves the object 10 metres north, and not 10 metres infront of the independant object which is what I want.

So how do I do this?  Im thinking a GetDir, but its the maths thats eluding me.
« Last Edit: 31 Aug 2002, 20:37:44 by [icarus_uk] »

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:Keeping position in a Setpos
« Reply #1 on: 01 Sep 2002, 03:18:47 »
I tested it. It works.

Code: [Select]
;_unit - The unit that is being "followed"
;_unit2 - _The object that is "following" the unit
;_rpos - direction relative to _unit1 _unit2 will be placed at (EXAMPLE: -179 through 180)
;_dis = distance to place _unit2 from _unit1
;
;Example: to have _unit2 allways stay 10meters in front of _unit1
;[unit1,unit2,0,10] exec "thisscript.sqs"
;


_unit = _this select 0
_unit2 = _this select 1
_rpos = _this select 2
_dis = _this select 3


#loop
_posx = getpos _unit select 0
_posy = getpos _unit select 1
_posz = getpos _unit select 2
_dir = getdir _unit
_unit2 setpos [_posx + ((sin (_dir + _rpos)) * _dis), _posy + ((cos (_dir + _rpos)) * _dis), _posz]
~0.1
goto "loop"
:)
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

MaZ

  • Guest
Re:Keeping position in a Setpos
« Reply #2 on: 02 Sep 2002, 10:11:38 »
f*ck me

been trying to do this for ages, but couldnt work out the maths (never been good with trig) thx toad :)