HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Blink Cast-Simulation

12-24-2006, 12:55 AM#1
xombie
I'm trying to simulate the casting of blink where as if you target a point say 5000 range from you, but the max range of blink is 800, it will keep the angle of the cast but reduce the range to 800. My code is as follows (for this range re-set):

For the sake of this question:
{max = 500}

Collapse JASS:
           if (SquareRoot((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1)) > max) then
               set ang = bj_RADTODEG * (Atan2((y2-y1), (x2-x1)))
               set x2  = max * Cos(ang * bj_DEGTORAD)
               set y2  = max * Sin(ang * bj_DEGTORAD)
           endif
x1/y1 are the coordinates of the caster, and x2/y2 are the coordinates of the spell location. Keep in mind that if I take these lines out of my code it works flawlessly, except there is no range control. Though it DOES re-create a location for the spell to target to, it is somewhat random. What I am asking is: Is there any bugs in this code?

Also, as a secondary question, I would like to know if you prefer being able to cast ANYWHERE on the map and have a maximum range, or being able to cast only a certain distance past the maximum.
12-24-2006, 01:05 AM#2
wyrmlord
From the looks of things you have a very simple error in the code.
Collapse JASS:
set x2 = max * Cos(ang * bj_DEGTORAD)
set y2 = max * Sin(ang * bj_DEGTORAD)

//The above is wrong, this is what you want instead:

set x2 = x1 + max * Cos(ang * bj_DEGTORAD)
set y2 = y1 + max * Sin(ang * bj_DEGTORAD)
I once had the same error in my code, it's pretty easy to overlook.

I'd prefer the function to not work the way Blink does. Instead, I think it should have a maximum casting range.
12-24-2006, 02:24 AM#3
xombie
Oh my, duh!! Lol wow I can't even believe myself. I was drunk when I wrote this code, but when revising it sober I should have caught myself. Anyways, thanks.