Home   Help Search Login Register  

Author Topic: Math prob  (Read 627 times)

0 Members and 1 Guest are viewing this topic.

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Math prob
« on: 15 Aug 2005, 13:52:52 »
IÂ've edited a script that creates random artillery in MP.
I place a GameLogic (GL1) on the map,as startpoint and I use a maximum range for the inpact of the next explosion.

Visual sight from top:



Say I use max = 1000m,the position of the next impact is:
Code: [Select]
?(local server):xpara = (random  Max);PublicVariable "xpara"
~0.7
?(local server):ypara = (random Max);PublicVariable "ypara"

Then I add the random generated x and y parameters to GL1 position...etc

But Random max will allways return a positive value between 0 and 1000,so the impact will allways happen in quadrant 1 (1/4th of the circle.)

To fix this,I run the code 4 times,and add manually the minus so I have:

xpara                    xpara                      -xpara                   -xpara
ypara                   -ypara                       ypara                   -ypara

The explosions will now cover the whole circle

My question :Is there something available so I dont have to run it 4 times and save PublicVariables?Hope I explained myself good enough.. :-[




http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Offline Blanco

  • Former Staff
  • ****
Re:Math prob
« Reply #1 on: 15 Aug 2005, 14:06:26 »
So you need a random number between -1000 and 1000?

Something like this?

Code: [Select]
_xmax = 1000
_xmax2 = _xmax *2
_min = (_xmax - _xmax)
_randomx = _min + (random _xmax2)
PublicVariable "randomx"

« Last Edit: 15 Aug 2005, 14:12:25 by Blanco »
Search or search or search before you ask.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Math prob
« Reply #2 on: 15 Aug 2005, 14:11:45 »
Rather that running the code several time why not select the range and the angle randomly:

_angle = random 360
_dist = random 1000

_xcoord = (getPos GL select 0) + _dist * sin (_angle)
_ycoord = (getPos GL select 1) + _dist * cos (_angle)

That way you would keep it all within the circle and you each quadrant would be equally likely each time the script is run, your method involves cycling through the quadrants if I understand correctly.  If you don't mind it being in a square then Blanco's suggestion will work

Ie:

_xcoord = (getPos GL select 0) -1000 + random 2000
ditto for y
« Last Edit: 15 Aug 2005, 14:17:59 by THobson »

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:Math prob
« Reply #3 on: 15 Aug 2005, 14:37:26 »
Allright!

That was just what my rusty brains needed,thanks alot Blanco and Thobson.

« Last Edit: 15 Aug 2005, 14:37:58 by Platoon Patton »
http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)