• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Maths!

Status
Not open for further replies.
Level 3
Joined
Nov 7, 2006
Messages
36
I'm working on a flash spell which flashes units within 400 radius. The duration of the flash effect depends on how far away the flashed units are and if they're facing the flash (if they're facing the flash they will be flashed for a longer time than if they're facing away from it). To calculate the distance factor is pretty simple, but I can't figure out how to calculate the facing factor. Any ideas?

Edit: The Flash is a fade filter

I posted some of my notes, don't know if it helps though.
 

Attachments

  • math notes.png
    math notes.png
    29.9 KB · Views: 93
Level 4
Joined
Apr 20, 2009
Messages
106
Alright, first I'll post up the trigger I was playing around with to get this to work, and then I'll explain it.

  • Events
    • Player - Player 1 (Red) types a chat message containing Test as An exact match
  • Conditions
  • Actions
    • Set Facing[1] = (Facing of Blood Mage 0001 <gen>)
    • Set Facing[2] = (Angle from (Position of Paladin 0000 <gen>) to (Position of Blood Mage 0001 <gen>))
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Facing[1] Less than or equal to (Facing[2] + 225.00)) and (Facing[1] Greater than or equal to (Facing[2] + 135.00))
      • Then - Actions
        • Game - Display to (All players) the text: Flashed
      • Else - Actions
        • Game - Display to (All players) the text: (String(Facing[1]))
        • Game - Display to (All players) the text: (String(Facing[2]))
Alright, so first, the Facing is a Real Array. I used it to store two different numbers, as you can see, but you could use two different variables or whatever you want.

So lets say that Paladin, the unit casting your flash spell, and Bloodmage, the unit getting flashed, are on a horizontal line. The angle between them is 0 or 360, and we're going to call it x. We will say that to be facing the Paladin, the Bloodmage needs to be looking within 45 degrees of where the Paladin is. I probably said that wrong, so I'll keep going...

Paladin ---------- Bloodmage

Lets say our Bloodmage is facing north, or 90 degrees, and we'll call that y. To find out whether or not he's facing, there's the simple condition.

If (y+(180-45)) <= x <= (y+(180+45)) Then
He's facing

So with the setup I described above, where x = 0 and y = 90...

90 + 135 = 225
90 + 225 = 315

So y doesn't fit the conditions as written above, so the Bloodmage is not facing the Paladin.

New scenario, the Bloodmage is at a 45 degree angle from the Paladin, and the Bloodmage is facing 190 degrees.

x = 45
y = 190
190 + 135 = 325
190 + 225 (Keep in mind the degrees) = 55

325 <= 45 <= 55

So y fits the conditions, so the Bloodmage is facing the Paladin.

I hope this makes sense, my logic is a bit runaround and messy, but you should be able to get enough from it to make it work with your trigger. If I missed anything, go ahead and shout at me :)
 
Level 3
Joined
Nov 7, 2006
Messages
36
Hm... I do understand what you're saying, though unfortunately it seems I wasn't clear enough (sorry for that). The casters angle don't matter, only the angle (Edit: and position in relativity to the position of the caster) of the flashed unit. Imagine three units standing on a horizontal line. The unit to the left is facing north, 90 degrees, and the unit to the right is facing west, 180 degrees. The unit in the middle uses flash and the unit to the left is flashed half as long as the unit to the right. The unit to the right get a maximum flash duration, since its directly facing the flashing unit. If the left unit would instead face north-east, 45 degrees, it would be flashed for 3/4 of max duration.
 
Level 4
Joined
Apr 20, 2009
Messages
106
I believe I have an idea of how I could get that to work, I'll play with it some more tonight and get back to you. For now, though, recheck my first trigger. It doesn't ever check the facing of the caster, just the facing of the Bloodmage, who is considered the victim. The Paladin is the 'caster' for that test.

Anyways, I'll get back to playing with it later :)
 
Level 3
Joined
Nov 7, 2006
Messages
36
Yes, that is indeed true :) Though it only gives a true or false, is the target facing the caster or not. I need to get a number on "how much the target is facing the caster". Anyways, I really appreciate that you're helping me to solve this.

I've come up with a part of the solution myself, though its not final. If the angle between points is called "v" and the facing of the target is "x" the time factor "z" will be:

z = (x - v) / 180

This only works if x - v =< 180 and x > v so its not solved yet.
 
Level 4
Joined
Apr 20, 2009
Messages
106
Here's what I've been considering. It works for most cases, but I've hit a couple snags. I haven't put it into trigger form yet and tested it out.

v = angle between points
x = facing of victim unit
z = flash multiplier (I'll get to that in a minute)

z = abs((abs(z) - abs(x)) / 180)

z would then be multiplied by what I call the flash constant. If the target was facing the caster, it would get a z value near 1, so it would get a nearly full flash time. If it was facing nearly opposite, it would get a very short flash.

Again, this seems to have some issues, working on it right now.
 
Level 3
Joined
Nov 7, 2006
Messages
36
Could you explain "abs" to me? Dunno which, but either I've forgot what it is or I've never known what it is or its something different in English, which i doubt. That z multiplier is precisely what I'm looking for btw :)
 
Level 9
Joined
Oct 11, 2009
Messages
477
"abs" stands for an absolute value of a number. Even if the number returns negative, it will be changed automatically to its positive value because there is no negative angle.
 
Level 3
Joined
Nov 7, 2006
Messages
36
Aha, like abs(z) = |z|.

Edit: it seems like your solution has the same problems as mine. Maybe the best solution would be to use different formulas in different situations.
 
Last edited:
Status
Not open for further replies.
Top