View Full Version : Random Location - Offsets
corley
07-21-2012, 03:57 PM
I am making an item spawn system from a dead unit, the problem is when i spawn multiple units based off the location of the dead unit they all appear on top of each other and its difficult to see each individual item. How would i make a random location based off a dying unit or offset to make each item appear slightly apart?
Thanks,
Corley
Mr_Bean
07-21-2012, 04:08 PM
If you use vJASS, something like this:
scope Test initializer onInit
globals
private constant real MIN_OFFSET = 100.0
private constant real MAX_OFFSET = 250.0
endglobals
private function offsetTest takes nothing returns boolean
local real dist = GetRandomReal(MIN_OFFSET, MAX_OFFSET)
local real ang = GetRandomReal(1.0, 360.0)
local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())
local real x2 = x + dist * Cos(Deg2Rad(ang))
local real y2 = y + dist * Sin(Deg2Rad(ang))
// More actions...such as:
call CreateItem('bspd', x2, y2)
return false
endfunction
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddCondition(t, Condition(function offsetTest))
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
set t = null
endfunction
endscope
This simply creates Boots of Speed at a random point within 250 distance from a dying unit.
Maker
07-21-2012, 05:00 PM
In gui, it is:
set loc1 = Position of Dying unit
set loc2 = loc1 offset by random number between x and y toward random angle
Create item at loc 2
Remove leaks
Of course, if you want a uniform distribution of items, you might want to take a random X and a random Y coordinate and check for it's distance to the unit.
I say this because, out of experience, I know that taking random numbers and using them as polar coordinates tends to give positions closer to the center more often than it does further outside.
corley
07-21-2012, 10:38 PM
would this work:
Set BossDrop_Point = ((Position of (Dying unit)) offset by ((Random real number between -50.00 and 50.00), (Random real number between -50.00 and 50.00)))
Maker
07-21-2012, 11:41 PM
Set point = (Position of (Dying unit))
Set point2 = (point offset by (Random real number between 0.00 and 64.00) towards (Random angle) degrees)
Item - Create Claws of Attack +15 at point2
Custom script: call RemoveLocation(udg_point)
Custom script: call RemoveLocation(udg_point2)
defskull
07-22-2012, 12:25 PM
corley, your trigger will work but it leaks, plus don't use negative as it would turn out the same result as positive, only random values.
Maker has showed you the way and it won't leak in any way, also a range from 0 to 64 unit range from the dying unit that the item will spawn.
corley
07-22-2012, 03:45 PM
Thanks, its working now i was just trying to be clever/lazy and only use on variable but Makers method works perfectly - thanks all for help +rep all round
defskull
07-22-2012, 09:41 PM
Thanks, its working now i was just trying to be clever/lazy and only use on variable but Makers method works perfectly - thanks all for help +rep all round
Your action was indeed a clever action, but not clever enough to tackle the "leaks" problem :)
Your trigger basically shortens the function (by not setting location into variable) but you will be having problems with leaks afterwards.
You can even set the random location without the use of points at all, just coordinates (Real).
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.
Search Engine Optimization by
vBSEO 3.5.1 PL2