• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Pick units in a cone shape

Status
Not open for further replies.
Level 22
Joined
Dec 31, 2006
Messages
2,216
That is quite easy.

A cone is in it's essence just a piece of a circle which is cut off with a certain angle.

So, here is the procedure:

First, choose a point that represents the tip of the cone. Then you need the length of the cone (basically the radius of the circle that the cone is cut out off). After that you need to choose an angle that will represent the direction of the cone (consider it a line going from the tip to the end through the centre of the cone). Finally, you need an additional angle which represents how wide the cone is. Choosing the angle 45 here will result in your cone being 1/4 of a whole circle. 90 degrees results in 1/2 of a whole circle, and 180 will give you a whole circle. This angle basically represents the angle between the centre line and the edge of the cone.

Then you pick every unit in a circle around the tip of the cone with a radius equal to the length of the cone. Then you need to measure the angle between the tip of the cone, and the picked unit. If the absolute value (the value without any minus sign) of this angle, minus the direction of the cone, is less than the angle you chose which represents how wide the cone is, then the unit is in your cone.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
TRD gave you a pretty good explanation.

I won't just give you trhe trigger since it is better to learn yourself and I'm sure you can do it. But here's some mathematical advice.

Cos(a,b) returns the angle difference of angles a and b. Cos returns values between -1 and 1. A could be the angle you're checking, from tip to unit for example. B could be the angle from the tip to the end.
 
Status
Not open for further replies.
Top