HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need to save the point of unit in region and move to matching point in other region

12-09-2003, 02:51 AM#1
FerretDruid
I have 4 regions which are the exact same width/height. I'm trying to move a unit (or, ALL units, rather) from one region to the other, in their exact same positions using text commands.

Example: So, I have 3 riflemen at the bottom left, 2 footmen at the top, and 1 priest in the middle of region A - I want them all moved to their exact same positions, but in region B instead.

I'm actually trying to do this as I type, I just paused to post as I am having poor luck figuring it out. It may just be that it requires math skills that I don't have, or something ;) Thanks for help in advance!
12-09-2003, 04:34 AM#2
Extrarius
What you need to do is something like for each unit in region A, calculate (position of unit) - (center of region A) and move unit instantly to (center of region B) + (position of unit) - (center of region A). Note that I don't think JASS lets you directly add positions, so you will need to do that for both the X and Y coordinates and then recombine those to a point.
12-09-2003, 04:59 AM#3
FerretDruid
I think I can see what you mean, but that mostly went over my head. Let me explain what I think you meant (or what I think might work, based from what you said).

For every unit in region A - save their current position as a variable (or 2) representing the 2 offsets ? Let's say from the very center of the region A, for simplicity - offset by X and Y. Then move to center of region B offset by X and Y?

A couple issues I have are getting those positions to a variable. I don't know how to set it properly. Maybe that's exactly what you just said, I don't know hehe. I see there is already a trigger to move to center of region with offset, etc. So the second part should be easy!
12-09-2003, 05:05 AM#4
Ligature
You won't even need variables! Just

move (TheUnit) to (Center of (Destination Region) offset by (X of position of TheUnit - X of center of (starting Region)), (Y of position of TheUnit - Y of center of (starting region)))

Edit - Think there's a Math function to calculate the X and Y offset between two points - using that would simplify it even further
12-09-2003, 05:19 AM#5
FerretDruid
You da man Ligature :D That works perfectly, thanks!

I suppose a math function isn't really gonna be needed unless I need to make many variations of this trigger, but as it is it's just a simple "move everything to the other place" trigger.