• 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.

Trigonometry/Math Help Please !

Status
Not open for further replies.
Level 17
Joined
Jul 1, 2010
Messages
720
I'm trying to make something like in the following picture:
View attachment 115132

The red dot is the unit to be protected and the black squares are all guards and basically what I want to do is to make the units move in a caravan manner. The red unit walks to a control point and whatever his facing angle is all of the guards are around him in the same initial positions. I hope I made myself understood. However he turns they turn around him but keep their offsets and facing the same angle as the red dot. I really suck at this, I've been trying to learn this stuff but I can't apply it at all. Can someone please explain these stuff in some commentaries to me as showing me would do no good. I REALLY WANT to learn these things so please a little help if you may !
It can be in JASS or triggers, it doesn't matter...if anyone needs my help in returns I'll gladly offer it.
 
Last edited:
Level 17
Joined
Jul 1, 2010
Messages
720
If you're familiar with the Frozen Throne Night Elf Campaign mission 06, the one where you have to escort Kael'thas and his caravans accros the river and they have a formation like behaviour, that's what I'm trying to achieve. I've looked over the code but I can't understand much of it. The red dot is the caravan and the black ones are the guards, they all have specific locations in relation to the caravan and wherever the caravan moves they keep their locations in relation to their initial locations.
 
a simple Escort System;

JASS:
/*
===Escort
===Created by Mckill2009
*/

library Escort

globals
    private constant integer       ATTACK = 851983
    private constant integer         MOVE = 851986
    private constant integer        SMART = 851971
endglobals

native UnitAlive takes unit u returns boolean

struct Escort
    unit hero
    unit guard
    real angle
    real atk
    real offset
    
    private static real maxXY = 1000000
    private static real interval = 0.5 //recommended
    private static timer t = CreateTimer()
    private static integer ins = 0
    private static integer array indexAr
    
    static method distGet takes real x1, real y1, real x2, real y2 returns real
        return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)
    endmethod
    
    static method looper takes nothing returns nothing
        local thistype this
        local integer i = 0
        local integer order
        local real a
        local real x
        local real y
        local real x1
        local real y1
        local real distX
        loop
            set i = i + 1  
            set this = indexAr[i]
            if UnitAlive(.hero) and UnitAlive(.guard) then
                set .atk = .atk + interval
                set a = GetUnitFacing(.hero) * bj_DEGTORAD
                set order = GetUnitCurrentOrder(.hero)
                set x = GetUnitX(.hero)
                set y = GetUnitY(.hero)
                set x1 = x+.offset*Cos(.angle+a)
                set y1 = y+.offset*Sin(.angle+a)
                if GetUnitCurrentOrder(.guard)==0 then
                    call IssuePointOrderById(.guard,ATTACK,x1,y1)
                endif           
                if order==MOVE or order==SMART and .atk > 3 then    
                    set .atk = 0
                    call IssuePointOrderById(.guard,ATTACK,x1,y1)
                endif
                set distX = distGet(x,y,GetUnitX(.guard),GetUnitY(.guard))
                if distX > maxXY then
                    call IssuePointOrderById(.guard,MOVE,x1,y1)
                endif
            else
                call .destroy()
                set indexAr[i] = indexAr[ins]
                set indexAr[ins] = this
                set ins = ins - 1   
                set i = i - 1
                if ins==0 then
                    call PauseTimer(t)
                endif  
            endif
            exitwhen i==ins
        endloop
    endmethod    
    
    static method regGuard takes unit hero, unit guard, real offset, real angle returns nothing
        local thistype this = allocate()
        set .hero = hero
        set .guard = guard
        set .offset = offset
        set .angle = angle * bj_DEGTORAD
        set .atk = 0
        if ins==0 then
            call TimerStart(t, interval, true, function thistype.looper)
        endif      
        set ins = ins + 1
        set indexAr[ins] = this
    endmethod
endstruct

endlibrary


use it;
  • Escort DEMO
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set U = Archmage 0190 <gen>
      • Set U1 = Footman 0201 <gen>
      • Custom script: call Escort.regGuard(udg_U,udg_U1,200,90)
      • Set U1 = Rifleman 0203 <gen>
      • Custom script: call Escort.regGuard(udg_U,udg_U1,200,180)
 
Status
Not open for further replies.
Top