HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

idk

12-29-2009, 03:34 AM#1
Zandose
Basically I created a center unit with a bunch of other units around it. I want all the units around the center unit to move, keep their correct distance, and rotate with the center unit. How would I do this?
12-29-2009, 04:08 AM#2
grim001
You didn't put much effort into your post. You should be more specific about whether you already know anything about how to approach the problem or not. Do you code in GUI or JASS? Do you know anything about polar offsets?

Anyway, you need to use a periodic timer to update the positions of all of the surrounding units. You can figure out the positions each unit should have by doing a polar offset in the direction the central unit is facing for the first unit, then incrementing the angle by (360/number of surrounding units) for the next unit, and so on.
12-29-2009, 05:05 AM#3
Zandose
Quote:
You didn't put much effort into your post.
Sorry. Guess I didn't put much thought into that.

Quote:
You should be more specific about whether you already know anything about how to approach the problem or not. Do you code in GUI or JASS? Do you know anything about polar offsets?
JASS please. For the love of god, no GUI please.

Quote:
Anyway, you need to use a periodic timer to update the positions of all of the surrounding units. You can figure out the positions each unit should have by doing a polar offset in the direction the central unit is facing for the first unit, then incrementing the angle by (360/number of surrounding units) for the next unit, and so on.
I already thought along those lines, but I thought there might be another way, more optimized, like vectors.
12-29-2009, 06:38 AM#4
grim001
It'd be easy if you didn't want to make them rotate along with the unit's facing. You could just use a constant x/y offset (that you calculate initially using polar projections) for each of the surrounding units. But since you would need to rotate the offset vectors, you wind up needing to do Cos/Sin stuff anyway.
12-29-2009, 11:29 AM#5
Anitarf
Quote:
Originally Posted by grim001
It'd be easy if you didn't want to make them rotate along with the unit's facing. You could just use a constant x/y offset (that you calculate initially using polar projections) for each of the surrounding units. But since you would need to rotate the offset vectors, you wind up needing to do Cos/Sin stuff anyway.
Well, he could still make use of precalculated relative x and y coordinates, because in that case he only needs to calculate cos and sin once for the entire group of units, rather than for each individual orbiting unit. Unless you have a ton of orbiting units for each center unit, though, this is a rather insignificant optimization.
12-30-2009, 03:31 AM#6
Zandose
Quote:
Originally Posted by Anitarf
Well, he could still make use of precalculated relative x and y coordinates, because in that case he only needs to calculate cos and sin once for the entire group of units, rather than for each individual orbiting unit. Unless you have a ton of orbiting units for each center unit, though, this is a rather insignificant optimization.
Could you please expand about usage of cos/sin. I currently have a max of 8 units following one main unit.
01-04-2010, 12:22 AM#7
thehellman
He is referring to the trigonometric functions you'll need to perform what you want.

Look the JASS function PolarProjectionBJ to understand how it works. You give it a location, it'll return a location that is projected forward by the amount you want, in the angle you want.

Example:

some location = GetLocationOfYourUnit()
PolarProjection(location, 50, towards angle)

What he was saying is that it doesn't always have to be calculated since they are always in the same distance.

I whipped up a demo map for you, so you can see a more practical way of how it works.
NOTE: You cannot use this in your map. It leaks locations, and you'll have to optimize it. I just did it in 5 minutes so you can have an idea.
Attached Files
File type: w3mdemoMap.w3m (16.3 KB)