Well, you would get the world coordinates of the unit and substract some specific coordinates of the first region, for example the center and add the same specific coordinate of the 2nd region, something like this:
x2 = x - CenterX(Region1) + CenterX(Region2)
x would be the x coordinate of the unit in the world, x2 is your result, the desired coordinate for the unit in the 2nd region.
CenterX refers to the x coordinate of the center of the region.
There should be functions to get the location of a unit and the center point of a region, also you should be able to retrieve the x and y coordinates of these points separately.
You could also use the distance between points function combined with the angle between points function to figure out a unit's position relative to the center of a region. Store those numbers in variables, then recall them for the second region to place the spawned units.
1. get the offset of the unit from region A's center:
offsetX = x coordinate of ( position of ( unit) ) + x coordinate of ( center of region A )
offsetY = y coordinate of ( position of ( unit ) ) + y coordinate of ( center of region A )
2. create the new unit within region B with the offset from region B's center:
newX = x coordinate of (center of region B) + offsetX
newY = y coordinate of (center of region B) + offsetY
Create type of (unit) at point (newX, newY)
That's quite simple to understand I guess.
If not, take a pencil and a paper and draw it.
The "script" you thought of describes that you would iterate over every unit within the location.
All answers provided focused on answering the position calculations and not when it will be used.
Kueken used x,y offsets like me. BasharTeg used distance + angle.
Both approaches are perfectly fine.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I cant figer out how to get the coordinates of a building in a region and to spawn a unit with this coordinates in a other region.
(sorry for my bad english i hope the image help to understand what i want to do)
Well, you would get the world coordinates of the unit and substract some specific coordinates of the first region, for example the center and add the same specific coordinate of the 2nd region, something like this:
x2 = x - CenterX(Region1) + CenterX(Region2)
x would be the x coordinate of the unit in the world, x2 is your result, the desired coordinate for the unit in the 2nd region.
CenterX refers to the x coordinate of the center of the region.
There should be functions to get the location of a unit and the center point of a region, also you should be able to retrieve the x and y coordinates of these points separately.
You could also use the distance between points function combined with the angle between points function to figure out a unit's position relative to the center of a region. Store those numbers in variables, then recall them for the second region to place the spawned units.
Sounds complicated to me i tought about a script like this
For every unit of type X in Region A Spawn a unit i in Region B
so far it is no problem but the units should spawn in the same position of the Buildung
there will be between 1 and 230 buildings
For example P is the pool Z is zerg and X empty space
Region A with buildings
XXPXXPXX
XXXXXXXX
XXXPPXXX
Region B where the units spawn
XXZXXZXX
XXXXXXXX
XXXZZXXX
1. get the offset of the unit from region A's center:
offsetX = x coordinate of ( position of ( unit) ) + x coordinate of ( center of region A )
offsetY = y coordinate of ( position of ( unit ) ) + y coordinate of ( center of region A )
2. create the new unit within region B with the offset from region B's center:
newX = x coordinate of (center of region B) + offsetX
newY = y coordinate of (center of region B) + offsetY
Create type of (unit) at point (newX, newY)
That's quite simple to understand I guess.
If not, take a pencil and a paper and draw it.
The "script" you thought of describes that you would iterate over every unit within the location.
All answers provided focused on answering the position calculations and not when it will be used.
Kueken used x,y offsets like me. BasharTeg used distance + angle.
Both approaches are perfectly fine.