Problems with angle

darkbeer

Beer is Good!
Reaction score
84
Hey, i want my unit to be moved at a certain speed into a certain direction. Its my first time using Radians instead of Degrees, unfortunately the unit moves totally wrong -.-

it moves very slow (althought the accerleration great enough) and in the absolute wrong direction

heres the code:
JASS:
                   set X = GetUnitX(dat.missile)
                    set Y = GetUnitX(dat.missile)
                    set targX = GetUnitX(dat.target)
                    set targY = GetUnitY(dat.target)
                    set angle = Atan2(targY - Y, targX - X)
                    call BJDebugMsg("angle: " + R2S(angle))
                    call BJDebugMsg("Angle Degree: " + R2S(angle * bj_RADTODEG))
                    call BJDebugMsg("X: " + R2S(X + dat.acceleration * Cos(angle)))
                    call BJDebugMsg("Cos: " + R2S(Cos(angle)))
                    call BJDebugMsg("UnitFacing Radians: " + R2S(GetUnitFacing(dat.missile)* bj_DEGTORAD))
                    call SetUnitPosition(dat.missile, X + dat.acceleration * Cos(angle), Y + dat.acceleration * Sin(angle))


EDIT: Something about thy Y coordinate musst be wrong -.-

thankfull for any suggestions^^
 
Reaction score
456
If you use degrees:
JASS:
set angle = Atan2(targY - Y, targX - X) * bj_RADTODEG

Maybe convert radians to degrees? Like you did not before :)

EDIT://Sorry, this happens when people don't read the first post carefully enough :p.. Don't do as I do ;D
 

darkbeer

Beer is Good!
Reaction score
84
:D, no problem guys, but i still have no solution :(

the Y is making me problems, not the X, sorry for that as well^^ heres the code:

JASS:
               set X = GetUnitX(dat.missile)
                    set Y = GetUnitX(dat.missile)
                    set targX = GetUnitX(dat.target)
                    set targY = GetUnitY(dat.target)
                    set angle = Atan2(targY - Y, targX - X) 
                    call BJDebugMsg("angle: " + R2S(angle))
                    call BJDebugMsg("Acc: " + R2S(dat.acceleration))
                    call BJDebugMsg("Y start: " + R2S(Y))
                    call BJDebugMsg("Y ohne Sin: " + R2S(Y + dat.acceleration))
                    call BJDebugMsg("Y: " + R2S(Y + dat.acceleration * Sin(angle)))
                    call BJDebugMsg("X: " + R2S(X + dat.acceleration * Cos(angle)))
                    call BJDebugMsg("Cos: " + R2S(Cos(angle)))
                    call BJDebugMsg("Sin: " + R2S(Sin(angle)))
                    call SetUnitPosition(dat.missile, X + dat.acceleration * Cos(angle) , Y + dat.acceleration * Sin(angle))


Instead of moving forward the unit moves backwards ...

In my test, the angle was about 90°, so the Sin would be 1 and the Y of the unit should increase by 100 (100 was testing acceleration) everytime, but it just doesnt, te starting Y was also 0 -.-

EDIT: OMG Im sorry my stupidity -.-, set Y to GetUnitX ..... Problem solved thanks everyone^^
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top