• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Angles and Polar Offset

Status
Not open for further replies.
Level 14
Joined
Jul 1, 2008
Messages
1,314
Hello guys,

i got a problem with polar offsets.

The Problem:

I want to create an artillery strike, and therefore create cross hairs around a bacon, which turn around, when the player presses right arrow or left arrow.

It works, but as you can see on the screenshots, the crosshairs dont move as a line, some of them even move without any event by the player.

I really have no idea, how this could be, so please help me :)

JASS:
function SheepArtillery_GetPlayerOrdersWaitForShoot takes nothing returns nothing

    local timer t          = GetExpiredTimer()
    local unit fadenkreuz1 = GetHandleUnit(t,"fadenkreuz1")
    
    local player p         = GetOwningPlayer(fadenkreuz1)
    local unit fadenkreuz2
    local unit fadenkreuz3
    local unit fadenkreuz4
    local unit fadenkreuz5
    local real ANGLE       = udg_SheepArtillery_Array[16] - udg_SheepArtillery_Array[15] // right = - ; left = +
    local real LVL         = udg_SheepArtillery_Array[2] 
    local real x1          = udg_SheepArtillery_Array[5] // posX of fadenkreuz1
    local real y1          = udg_SheepArtillery_Array[6] // posY of fadenkreuz1
    local real x2
    local real y2
    local real DIST        = 0.00
    
    // if Sheep Artillery fired ?
    if udg_SheepArtillery_Array[1] > 1.00 or udg_SheepArtillery_Array[4] == 1.00 then
       
       // destroy timer and reset fired, start reloading
       call PauseTimer(t)
       set udg_SheepArtillery_Array[1] = 0.00 // firing again possible
       set udg_SheepArtillery_Array[4] = 0.00 // Esc reset
       call RemoveUnit(fadenkreuz1)
       if LVL > 0.00 then
          set fadenkreuz2 = GetHandleUnit(t,"fadenkreuz2")
          set fadenkreuz3 = GetHandleUnit(t,"fadenkreuz3")
          call RemoveUnit(fadenkreuz2)
          call RemoveUnit(fadenkreuz3)
          if LVL > 1.00 then
             set fadenkreuz4 = GetHandleUnit(t,"fadenkreuz4")
             set fadenkreuz5 = GetHandleUnit(t,"fadenkreuz5")
             call RemoveUnit(fadenkreuz4)
             call RemoveUnit(fadenkreuz5)
          endif  
       endif
       call FlushHandleLocals(t)
       call DestroyTimer(t)  
    
    else
       
       // if upgraaded to lvl 2
       if LVL > 0.00 then
        
          set fadenkreuz2 = GetHandleUnit(t,"fadenkreuz2")
          set fadenkreuz3 = GetHandleUnit(t,"fadenkreuz3")
          
          // set the new angles, if player wants to change them
          // fadenkreuz 2
          set x2 = udg_SheepArtillery_Array[7]
          set y2 = udg_SheepArtillery_Array[8]
          set ANGLE = ANGLE + (bj_RADTODEG * Atan2(y2 - y1, x2 - x1))
          set x2 = x1 + 200.00 * Cos(ANGLE * bj_DEGTORAD)
          set y2 = y1 + 200.00 * Sin(ANGLE * bj_DEGTORAD)
          set udg_SheepArtillery_Array[7] = x2
          set udg_SheepArtillery_Array[8] = y2
          call SetUnitPosition(fadenkreuz2,x2,y2)
          
          // fadenkreuz 3
          set x2 = udg_SheepArtillery_Array[9]
          set y2 = udg_SheepArtillery_Array[10]
          set ANGLE = ANGLE + (bj_RADTODEG * Atan2(y2 - y1, x2 - x1)+180.00)
          set x2 = x1 + 200.00 * Cos((ANGLE) * bj_DEGTORAD)
          set y2 = y1 + 200.00 * Sin((ANGLE) * bj_DEGTORAD)
          set udg_SheepArtillery_Array[9]  = x2
          set udg_SheepArtillery_Array[10] = y2
          call SetUnitPosition(fadenkreuz3,x2,y2)
                    
          // if upgraaded to lvl 3
          if LVL > 1.00 then 
             set fadenkreuz4 = GetHandleUnit(t,"fadenkreuz4")
             set fadenkreuz5 = GetHandleUnit(t,"fadenkreuz5")
             
             // set the new angles, if player wants to change them
             // fadenkreuz 4
             set x2 = udg_SheepArtillery_Array[11]
             set y2 = udg_SheepArtillery_Array[12]
             set ANGLE = ANGLE + (bj_RADTODEG * Atan2(y2 - y1, x2 - x1))
             set x2 = x1 + 400.00 * Cos(ANGLE * bj_DEGTORAD)
             set y2 = y1 + 400.00 * Sin(ANGLE * bj_DEGTORAD)
             set udg_SheepArtillery_Array[10] = x2
             set udg_SheepArtillery_Array[11] = y2
             call SetUnitPosition(fadenkreuz4,x2,y2)
          
             // fadenkreuz 5
             set x2 = udg_SheepArtillery_Array[13]
             set y2 = udg_SheepArtillery_Array[14]
             set ANGLE = ANGLE + (bj_RADTODEG * Atan2(y2 - y1, x2 - x1)+180.00)
             set x2 = x1 + 400.00 * Cos((ANGLE) * bj_DEGTORAD)
             set y2 = y1 + 400.00 * Sin((ANGLE) * bj_DEGTORAD)
             set udg_SheepArtillery_Array[13] = x2
             set udg_SheepArtillery_Array[14] = y2
             call SetUnitPosition(fadenkreuz5,x2,y2)
             
          endif
       endif
       
    endif
    
    // reset
    set fadenkreuz1 = null
    set fadenkreuz2 = null
    set fadenkreuz3 = null
    set fadenkreuz4 = null
    set fadenkreuz5 = null
    set t = null
    set p = null
    
endfunction    
    
function Trig_Sheep_Artillery_set_Point_Actions takes nothing returns nothing

    // udg_SheepArtillery_Array [REAL]
    local unit art = gg_unit_o004_0096
    local player p = GetOwningPlayer(art)
    local real x = GetOrderPointX()
    local real y = GetOrderPointY()
    local timer t
    
    // is player owning player? ( still a little bug chance )
    if IsUnitSelected(art,Player(R2I(udg_SheepArtillery_Array[17]))) == true then
       // init sheep strike if possible
       if udg_SheepArtillery_Array[1] == 0.00 then
       
          // create fadenkreuze
          set t = CreateTimer()
       
          set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
          call SetHandleHandle(t,"fadenkreuz1",bj_lastCreatedUnit)
          set udg_SheepArtillery_Array[5] = x
          set udg_SheepArtillery_Array[6] = y
       
          call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"-[|c00ff0000Warning|r]-  Artillery-Bacon set to ("+I2S(R2I(x))+"/"+I2S(R2I(y))+")")
        
          // upgrade to Lvl 2 "fadenkreuze" already purchased?
          if udg_SheepArtillery_Array[2] > 0.00 then
             set y = y + 200.00
             set udg_SheepArtillery_Array[7] = x
             set udg_SheepArtillery_Array[8] = y
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz2",bj_lastCreatedUnit)
        
             set y = y - 400.00
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz3",bj_lastCreatedUnit)
                     
             set udg_SheepArtillery_Array[9]  = x
             set udg_SheepArtillery_Array[10] = y
          endif
          
          // upgrade to Lvl 3 "fadenkreuze" already purchased?
          if udg_SheepArtillery_Array[2] > 1.00 then
             set y = y + 600.00
             set udg_SheepArtillery_Array[11] = x
             set udg_SheepArtillery_Array[12] = y
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz4",bj_lastCreatedUnit)
        
             set y = y - 800.00
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz5",bj_lastCreatedUnit)
                     
             set udg_SheepArtillery_Array[13]  = x
             set udg_SheepArtillery_Array[14] = y
          endif   
               
          set udg_SheepArtillery_Array[1] = 1.00 // set unit firing step 1
       
          call TimerStart(t,0.50,true,function SheepArtillery_GetPlayerOrdersWaitForShoot)
         
       endif
    endif
    
    set t = null
    set p = null
    set art = null   
    
endfunction

//===========================================================================
function InitTrig_Sheep_Artillery_set_Point takes nothing returns nothing
    set gg_trg_Sheep_Artillery_set_Point = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Sheep_Artillery_set_Point, gg_unit_o004_0096, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_Sheep_Artillery_set_Point, function Trig_Sheep_Artillery_set_Point_Actions )
endfunction

The Screens

1. Start:


2. Some of the crosshairs begin to move on their own


3. 20 Seconds passed, and this is what happens:


4. Here is a screen, how i would like them to move:
-> All the crosshairs in a line, and of course the first is in the middle and doesnt have to move!
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Bacon as in food?

Anyhow, I really don't get your angle calculations, but it might just be because of your pretty-bad description.

According to what I understood, your angles should be something like this:

A = BaseAngle + 90
B = A + 180

A is for one side and B is for the other.

Here are a few examples
Code:
[U][I]Case A[/I][/U]
[B]BaseAngle[/B] = 45
[B]A[/B] = 135
[B]B[/B] = 315

[B]
A
  A
    X
      B
        B[/B]

[U][I]Case B[/I][/U]
[B]BaseAngle[/B] = 0
[B]A[/B] = 90
[B]B[/B] = 270

[B]A 
A 
X 
B 
B[/B]

[U][I]Case C[/I][/U]
[B]BaseAngle[/B] = 90
[B]A[/B] = 180
[B]B[/B] = 360

[B]A A X B B[/B]

Of course they should all be in radians, which leads me to the next point.
You take your angles, do calculations in radians, transform them to degrees, and then back to radians.
What's the point? Just stay with radians from the start.

And as my last point. You have a crosshair model (that aura). It would be better to just use that with animations for the rotations, unless you need the beacon to look differently in some cases.
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
1. sorry for this typing error *g*

2. Thanks Alot!, you understood me right :)
This is the new code, it works now :D

SOLVED

JASS:
function SheepArtillery_GetPlayerOrdersWaitForShoot takes nothing returns nothing

    local timer t          = GetExpiredTimer()
    local unit fadenkreuz1 = GetHandleUnit(t,"fadenkreuz1")
    // RADTODEG = 57.296
    // DEGTORAD =  0.01745
    // Pi       =  3.142
    local player p         = GetOwningPlayer(fadenkreuz1)
    local unit fadenkreuz2
    local unit fadenkreuz3
    local unit fadenkreuz4
    local unit fadenkreuz5
    local real ANGLE       = 0.175 *(udg_SheepArtillery_Array[16] - udg_SheepArtillery_Array[15]) // right = - ; left = +
    local real ANGLE_INV   = 0.00
    local real LVL         = udg_SheepArtillery_Array[2] 
    local real x1          = udg_SheepArtillery_Array[5] // posX of fadenkreuz1
    local real y1          = udg_SheepArtillery_Array[6] // posY of fadenkreuz1
    local real x2
    local real y2
    local real DIST        = 0.00
    
    // if Sheep Artillery fired ?
    if udg_SheepArtillery_Array[1] > 1.00 or udg_SheepArtillery_Array[4] == 1.00 then
       
       // destroy timer and reset fired, start reloading
       call PauseTimer(t)
       set udg_SheepArtillery_Array[1] = 0.00 // firing again possible
       set udg_SheepArtillery_Array[4] = 0.00 // Esc reset
       call RemoveUnit(fadenkreuz1)
       if LVL > 0.00 then
          set fadenkreuz2 = GetHandleUnit(t,"fadenkreuz2")
          set fadenkreuz3 = GetHandleUnit(t,"fadenkreuz3")
          call RemoveUnit(fadenkreuz2)
          call RemoveUnit(fadenkreuz3)
          if LVL > 1.00 then
             set fadenkreuz4 = GetHandleUnit(t,"fadenkreuz4")
             set fadenkreuz5 = GetHandleUnit(t,"fadenkreuz5")
             call RemoveUnit(fadenkreuz4)
             call RemoveUnit(fadenkreuz5)
          endif  
       endif
       call FlushHandleLocals(t)
       call DestroyTimer(t)
       if GetLocalPlayer() == p then
          call ResetToGameCamera(0)
       endif  
    
    else
       
       // if upgraaded to lvl 2
       if LVL > 0.00 then
        
          set fadenkreuz2 = GetHandleUnit(t,"fadenkreuz2")
          set fadenkreuz3 = GetHandleUnit(t,"fadenkreuz3")
          
          // set the new angles, if player wants to change them
          set x2 = udg_SheepArtillery_Array[7]
          set y2 = udg_SheepArtillery_Array[8]
          set ANGLE = ANGLE + Atan2(y2 - y1, x2 - x1)
          set ANGLE_INV = ANGLE + 3.14159
          
          // fadenkreuz 2
          set x2 = x1 + 200.00 * Cos(ANGLE)
          set y2 = y1 + 200.00 * Sin(ANGLE)
          set udg_SheepArtillery_Array[7] = x2
          set udg_SheepArtillery_Array[8] = y2
          call SetUnitPosition(fadenkreuz2,x2,y2)          
          // fadenkreuz 3
          set x2 = x1 + 200.00 * Cos(ANGLE_INV)
          set y2 = y1 + 200.00 * Sin(ANGLE_INV)
          set udg_SheepArtillery_Array[9]  = x2
          set udg_SheepArtillery_Array[10] = y2
          call SetUnitPosition(fadenkreuz3,x2,y2)
                    
          // if upgraaded to lvl 3
          if LVL > 1.00 then 
             
             set fadenkreuz4 = GetHandleUnit(t,"fadenkreuz4")
             set fadenkreuz5 = GetHandleUnit(t,"fadenkreuz5")

             // fadenkreuz 4
             set x2 = x1 + 400.00 * Cos(ANGLE)
             set y2 = y1 + 400.00 * Sin(ANGLE)
             set udg_SheepArtillery_Array[10] = x2
             set udg_SheepArtillery_Array[11] = y2
             call SetUnitPosition(fadenkreuz4,x2,y2)          
             // fadenkreuz 5
             set x2 = x1 + 400.00 * Cos(ANGLE_INV)
             set y2 = y1 + 400.00 * Sin(ANGLE_INV)
             set udg_SheepArtillery_Array[13] = x2
             set udg_SheepArtillery_Array[14] = y2
             call SetUnitPosition(fadenkreuz5,x2,y2)
             
          endif
       endif
       
    endif
    
    // reset
    set fadenkreuz1 = null
    set fadenkreuz2 = null
    set fadenkreuz3 = null
    set fadenkreuz4 = null
    set fadenkreuz5 = null
    set t = null
    set p = null
    
endfunction    
    
function Trig_Sheep_Artillery_set_Point_Actions takes nothing returns nothing

    // udg_SheepArtillery_Array [REAL]
    local unit art = gg_unit_o004_0096
    local player p = GetOwningPlayer(art)
    local real x = GetOrderPointX()
    local real y = GetOrderPointY()
    local timer t
    
    // is player owning player? ( still a little bug chance )
    if IsUnitSelected(art,Player(R2I(udg_SheepArtillery_Array[17]))) == true then
       // init sheep strike if possible
       if udg_SheepArtillery_Array[1] == 0.00 then
       
          // create crosshairs
          set t = CreateTimer()
       
          set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
          call SetHandleHandle(t,"fadenkreuz1",bj_lastCreatedUnit)
          set udg_SheepArtillery_Array[5] = x
          set udg_SheepArtillery_Array[6] = y
       
          if GetLocalPlayer() == p then
             call SetCameraTargetController(GetUnitRallyUnit(art),0.00,0.00,false)
          endif
          call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"[|c00ff0000Warning|r]  Artillery-Beacon set to ("+I2S(R2I(x))+"/"+I2S(R2I(y))+")")
        
          // upgrade to Lvl 2 "fadenkreuze" already purchased?
          if udg_SheepArtillery_Array[2] > 0.00 then
             set y = y + 200.00
             set udg_SheepArtillery_Array[7] = x
             set udg_SheepArtillery_Array[8] = y
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz2",bj_lastCreatedUnit)
        
             set y = y - 400.00
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz3",bj_lastCreatedUnit)
                     
             set udg_SheepArtillery_Array[9]  = x
             set udg_SheepArtillery_Array[10] = y
          endif
          
          // upgrade to Lvl 3 "fadenkreuze" already purchased?
          if udg_SheepArtillery_Array[2] > 1.00 then
             set y = y + 600.00
             set udg_SheepArtillery_Array[11] = x
             set udg_SheepArtillery_Array[12] = y
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz4",bj_lastCreatedUnit)
        
             set y = y - 800.00
             set bj_lastCreatedUnit = CreateUnit(p,'h00F',x,y,270.00)
             call SetHandleHandle(t,"fadenkreuz5",bj_lastCreatedUnit)
                     
             set udg_SheepArtillery_Array[13]  = x
             set udg_SheepArtillery_Array[14] = y
          endif   
               
          set udg_SheepArtillery_Array[1] = 1.00 // set unit firing step 1
       
          call TimerStart(t,0.50,true,function SheepArtillery_GetPlayerOrdersWaitForShoot)
         
       endif
    endif
    
    set t = null
    set p = null
    set art = null   
    
endfunction

//===========================================================================
function InitTrig_Sheep_Artillery_set_Point takes nothing returns nothing
    set gg_trg_Sheep_Artillery_set_Point = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Sheep_Artillery_set_Point, gg_unit_o004_0096, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_Sheep_Artillery_set_Point, function Trig_Sheep_Artillery_set_Point_Actions )
endfunction
 
Status
Not open for further replies.
Top