This tutorial is about dodging the WC3 bug when we want to detect an interval between 2 angles. If you already know how to do this don't read this tutorial.
This tutorial teaches a way you can use to check angles without using angles, only distances.
The reason for this is because WC3 has problems with it's angles, the angle between point goes from -180 to +180, which means you have a lot of problems when you want to detect if damage comes from behind, if units are inside a cone, if a unit is looking to the other, etc.
the problem:
If you have a simple spell that you want to get unit in a cone, which means:
Angle between (caster) and (enemy) is a value between ((angle between (caster) and (target point of ability beeing cast)) + or - 10).
if the angle between (caster) and (target point of ability beeing cast) is 175, the angle between (caster) and (target) must be between +185 and +165. But there is no +185 angle on warcraft!.
Usually you will create a very complicated trigger to dodge this problems, this tutorial will show an easier way to do this using mathematical logic.
I need any mathematical knoledge to do this?
No, you don't. I will only show and explain how the method works, and then, you just have to putthe values inside a formula.
---------------------------------------IF YOU DON'T UNDERSTOOD THE FORMULA READ THIS----------------
1 - First of all you have to use a damage detection system (but this is not a tutorial about damage systems, so, I'll not explain how to use them or create them).
2 - when a unit takes damage and this is a damage that results from an attack you have to pick a lot of points:
B as its center.
A as a point in the border of the circle.
C as another point in the border.
-ab- as the radius of the circle.
Using mathematical logic I can say that the the distance between B and A is equal to the radius, also, the distance between B and C is equal to the radius and equal to -ab-.
TO detect the angles we have to transform out circle into a rectangle triangle, for this, we just have to pick 2 distance values:
Do you remember that the angle between the source and the back of the target must be +or- 30 degrees?
So, just do this:
--------------end----------------------
This tutorial helped you?
Is this tutorial too abstract?
Is it to complicated?
Did you find any bug when using this?
Do you want help with other types of spells like cone detection, see if unit is looking to another, etc?
I'll check this tutorial for comments, and I can update it if someone is having troubles to use this mathematical content.
I Hope at least one person find help here.:thup:
Here is the demo map, it works PERFECTLY!
This tutorial teaches a way you can use to check angles without using angles, only distances.
The reason for this is because WC3 has problems with it's angles, the angle between point goes from -180 to +180, which means you have a lot of problems when you want to detect if damage comes from behind, if units are inside a cone, if a unit is looking to the other, etc.
the problem:
If you have a simple spell that you want to get unit in a cone, which means:
Angle between (caster) and (enemy) is a value between ((angle between (caster) and (target point of ability beeing cast)) + or - 10).
if the angle between (caster) and (target point of ability beeing cast) is 175, the angle between (caster) and (target) must be between +185 and +165. But there is no +185 angle on warcraft!.
Usually you will create a very complicated trigger to dodge this problems, this tutorial will show an easier way to do this using mathematical logic.
I need any mathematical knoledge to do this?
No, you don't. I will only show and explain how the method works, and then, you just have to putthe values inside a formula.
TUTORIAL
First of all, I must say that I'm going to use a backstab detection as example.
Imagine this spell:
Backstab (passive)
Everytime you hit an enemy from behind you deal 25 bonus damage.
Note: angle between target's back and damage source must be +or- 30 degrees.
THIS IS THE FORMULA! YOU CAN JUST USE IT IF YOU UNDERSTAND, IF NOT, READ THE REST OF THE TUTORIAL
this is the formula, you just have to change the value 30 to the limit angle you would like to use.
Code:set A = position of (damage source) set B = position of (triggering unit) set C = B offset by (distance between A and B) and (fancing of (triggering unit)) degrees. If (Cos(30/2)) < ((Distance between C and A) / ((Distance between C and B)x2) then do your action
No need for mathematical Knoledge, just use the formula above!
this is to prevent divisions by zero, but, I think it is almost impossible to have a distance between target and sorce equal to zero...so, use it just if you think your map could lead to a value like 0, if not, just use the first formula)Code:set A = position of (damage source) set B = position of (triggering unit) set C = B offset by (distance between A and B) and (fancing of (triggering unit)) degrees. set cb = (distance between C and B) x 2 if cb = 0 then (set cb = 0.01) If (Cos(30/2)) < ((Distance between C and A) / (cb) then do your actions
you can download the demo map in the bottom of this post and just Copy and Paste the trigger inside your map
---------------------------------------IF YOU DON'T UNDERSTOOD THE FORMULA READ THIS----------------
1 - First of all you have to use a damage detection system (but this is not a tutorial about damage systems, so, I'll not explain how to use them or create them).
2 - when a unit takes damage and this is a damage that results from an attack you have to pick a lot of points:
after you pick all the 3 points listed above you will have a mathematical circle with:A = the position of the damage source.
B = the position of the target.
-ab- = the distance between A and B.
C = B offset by -ab- and (facing of target)
B as its center.
A as a point in the border of the circle.
C as another point in the border.
-ab- as the radius of the circle.
Using mathematical logic I can say that the the distance between B and A is equal to the radius, also, the distance between B and C is equal to the radius and equal to -ab-.
TO detect the angles we have to transform out circle into a rectangle triangle, for this, we just have to pick 2 distance values:
Then we detect a Cosine:Hip = 2x(Distance between C and B)
Cat = Distance between A and C.
The only thing we will use now is this Cosine.Cosine = Cat / Hip
Do you remember that the angle between the source and the back of the target must be +or- 30 degrees?
So, just do this:
set Limit_Cosine = Cosine of (30/2) degrees
check if Cosine > Limit_Cosine
--------------end----------------------
This tutorial helped you?
Is this tutorial too abstract?
Is it to complicated?
Did you find any bug when using this?
Do you want help with other types of spells like cone detection, see if unit is looking to another, etc?
I'll check this tutorial for comments, and I can update it if someone is having troubles to use this mathematical content.
I Hope at least one person find help here.:thup:
Here is the demo map, it works PERFECTLY!