Welcome, Guest Thursday 24th April 2014, 04:16:46
   Home   Help Search Login Register  

OFPEC Forum

Author Topic: [SOLVED] Math help! Moving towards centre of circle  (Read 309 times)
0 Members and 1 Guest are viewing this topic.
Wolfrug
Addons Depot
Administrator
*****
Offline Offline


Official OFPEC Old Timer


« on: 29 Oct 2010, 20:08:52 »

For you math wizards!

Scenario:

A person steps outside a circle, and is subsequently teleported back inside it (activated in a trigger's On Deactivation field, basically). This could be done simply by moving the unit, say, 5 meters in the direction of the centre of the circle (getPos TriggerName). What math wizardy would I need to perform to be able to do this rather simple operation? I suck at math, so all I basically need is the function, explanations will be useless Embarrassed (I bet it involves tan and sin and all those scary buggers).

Tried to search for this, but failed. So thanks!

Wolfrug out.
« Last Edit: 09 Nov 2010, 14:52:43 by Wolfrug » Logged

"When 900 years YOU reach, look as good you will not!"
laggy
*
Offline Offline


"Behold a pale horse"


« Reply #1 on: 29 Oct 2010, 22:39:11 »

I suck at math as well  Embarrassed

But, why not run a script on the unit measuring:

Code:
while {true} do
      {
      if (myUnit distance myCenter > 95) then {_spot = getPos myUnit};
      if (myUnit distance myCenter > 100) then {myUnit setPos _spot};
      sleep 1;
      }

Sorry if I got it completely wrong... It is late on a Friday night Tongue

I guess that could make the player/unit slowly "crawl" out of the wanted zone, if really persistant.
« Last Edit: 29 Oct 2010, 22:42:55 by laggy » Logged

And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.
JamesF1
Editors Depot Staff
*****
Offline Offline



WWW
« Reply #2 on: 29 Oct 2010, 23:23:49 »

It's too late in the day for me to do math (it doesn't come as naturally to me as I'd like Wink), but you could make use of CBA and BIS functions thus (if in doubt, leave the real math to people who can do it Cheesy):
Code:
_initial = getPosATL player;
_trigger = getPosATL yourTriggerName;
_direction = [_initial, _trigger] call BIS_fnc_relativeDirTo;
_vector = [5, _direction, 0] call CBA_fnc_polar2vect;
_position = [_initial, _vector] call CBA_fnc_vectAdd;
player setPosATL _position;
player setDir _direction;
I've not tested that, but that should take them 5 metres towards the centre.  If not, then please do blame my late night attempts at comprehending questions and providing answers Wink
« Last Edit: 29 Oct 2010, 23:25:26 by JamesF1 » Logged
Mr.Peanut
Former Staff
****
Offline Offline

urp!


« Reply #3 on: 29 Oct 2010, 23:35:49 »

Code:
_r = 5;
_xt = (getPos _trigger) select 0;
_yt = (getPos _trigger) select 1;
_xu = (getPos _unit) select 0;
_yu = (getPos _unit) select 1;
_dx = _xu - _xt;
_dy = _yu - _yt;
_dir = _dy atan2 _dx;
_dx = _dx - _r * cos _dir;
_dy = _dy - _r * sin _dir;
_unit setPos (_xt + _dx, _yt + _dy, 0);
« Last Edit: 29 Oct 2010, 23:38:16 by Mr.Peanut » Logged

urp!
Wolfrug
Addons Depot
Administrator
*****
Offline Offline


Official OFPEC Old Timer


« Reply #4 on: 09 Nov 2010, 14:52:28 »

I forgot to say thank you to Mr. Peanut: thank you! That solved it, no problems whatsoever. Now all I'd need would be a command to setdir the player in the exact direction of the centre of the trigger, but that's really a secondary matter after all Wink

Thanks again everyone!

Wolfrug out.
Logged

"When 900 years YOU reach, look as good you will not!"
bedges
Administrator
*****
Offline Offline


WWW
« Reply #5 on: 09 Nov 2010, 15:08:02 »

You may find that _dir in Peanut's example above is the angle you seek.
Logged
Pages: [1]   Go Up
  Send this topicPrint  
 
Jump to: