HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell: Fear - trouble

05-09-2007, 04:03 PM#1
Fulla
Fear Forces all nearby enemy units to run away in fear.


Orange = Caster
Red = Enemy Units
Blue = Location to order them to move

My script doesnt seem to be working properly
Collapse JASS:
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    loop
        set d = FirstOfGroup(g)
        exitwhen d == null
        set x1 = GetUnitX(d)
        set y1 = GetUnitY(d)
        set a = .017453 * Atan2(x1 - x, y1 - y)
        set x1 = x1 + 600. * Cos(a * 57.29582)
        set y1 = y1 + 600. * Sin(a * 57.29582)
        call IssuePointOrderById(d, 851986, x1, y1)
        call GroupRemoveUnit(g, d)
    endloop

Is the maths correct?
05-09-2007, 04:15 PM#2
Toink
Math is correct, but you haven't enumerated/added them to the group yet silly.
05-09-2007, 04:34 PM#3
blu_da_noob
Maths is wrong. Should be set a = .017453 * Atan2(y1 - y,x1 - x).
Remember kids, gradient is dy/dx.

Edit: PS, you can remove both your multiplications there, you're converting from radians to degrees to radians for no real reason.
05-09-2007, 04:37 PM#4
Toink
I use X/Y + <Dist> * Sin/Cos( a * bj_DEGTORAD )
05-09-2007, 05:08 PM#5
blu_da_noob
Quote:
Originally Posted by Toink
I use X/Y + <Dist> * Sin/Cos( a * bj_DEGTORAD )

I'm not sure exactly what you are trying to say here, because that's not really relevant on its own. You only need to multiply by bj_DEGTORAD if you store your angle in degrees instead of radians. If you only ever use your angle for a sin and a cos call, it makes no sense to convert back and forth.
05-09-2007, 05:17 PM#6
Toink
That's how the PolarProjectionBJ function does it.. :/

So what you're implying is that I only need to do this : Set x = x + dist * Sin(a) ??
05-09-2007, 05:22 PM#7
grim001
I prefer the vector method of doing this, it should be faster and either way it looks better to me.

m = SquareRoot(dx*dx + dy*dy)
newx = x + distance*(dx/m)
newy = y + distance*(dy/m)

as an added bonus this easily translates into 3 dimensions

m = SquareRoot(dx*dx + dy*dy + dz*dz)
newx = x + distance*(dx/m)
newy = y + distance*(dy/m)
newz = z + distance*(dz/m)

this is for extending/shrinking straight lines as you showed in your picture.
05-09-2007, 05:22 PM#8
Fulla
Aha thx guys, prob solved :p
05-09-2007, 05:25 PM#9
Toink
I'm not really good at math, considering the fact that I've only just taken up Algebra 1..

Quote:
Originally Posted by Fulla
Aha thx guys, prob solved :p

Np. Try not to overlook the code, I do that alot and often screw myself up trying to figure out what's wrong.