Home   Help Search Login Register  

Author Topic: [SOLVED] Math help! Moving towards centre of circle  (Read 1625 times)

0 Members and 1 Guest are viewing this topic.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
[SOLVED] Math help! Moving towards centre of circle
« on: 29 Oct 2010, 21: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 :-[ (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 »
"When 900 years YOU reach, look as good you will not!"

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Math help! Moving towards centre of circle
« Reply #1 on: 29 Oct 2010, 23:39:11 »
I suck at math as well  :-[

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

Code: [Select]
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 :P

I guess that could make the player/unit slowly "crawl" out of the wanted zone, if really persistant.
« Last Edit: 29 Oct 2010, 23:42:55 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Math help! Moving towards centre of circle
« Reply #2 on: 30 Oct 2010, 00: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 ;)), but you could make use of CBA and BIS functions thus (if in doubt, leave the real math to people who can do it :D):
Code: [Select]
_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 ;)
« Last Edit: 30 Oct 2010, 00:25:26 by JamesF1 »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Math help! Moving towards centre of circle
« Reply #3 on: 30 Oct 2010, 00:35:49 »
Code: [Select]
_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: 30 Oct 2010, 00:38:16 by Mr.Peanut »
urp!

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Math help! Moving towards centre of circle
« 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 ;)

Thanks again everyone!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: [SOLVED] Math help! Moving towards centre of circle
« Reply #5 on: 09 Nov 2010, 15:08:02 »
You may find that _dir in Peanut's example above is the angle you seek.