• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Gyro's Missile acceleration?

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
You have
Speed
Acceleration

Speed is 0 for 3 seconds. Acceleration is 0 for 3 seconds.

Then speed goes to about 300/second + Acceleration, which is 0.
So: Set Point1 = position of Missile and Point2 = Point1 Offset by Speed towards Target

Then, you increase acceleration by 5. and again set Speed = Speed+Acceleration. and Set Point1 = position of Missile and Point2 = Point1 Offset by Speed towards Target

That will make the missile speed increase gradually. A simple ITE will stop acceleration increase.

The first time it's 300. Then 305, Then 310, Then 315, then 320, and so on. Just play with the values untill you find a speed/acceleration rate you like.

Since it requires a 0.03 loop to make the movement smooth, you should multiply all these values by 0.03.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
GUI or JASS?

EDIT: I Hope it's JASS: Take a minute to read all the code, functions, and comments. Try to see the logic in all that stuff, and always feel free to ask anything you want. I tested and works perfectly. It's a bit fast though, thankfully really easy to modify.

JASS:
globals
    hashtable MissileHash = InitHashtable()
    real MissileSpeed = 6 // This is 200 * 0.03
    real MissileAcceleration = 0.15 // This is 5 * 0.03
    integer MissileAbilityId = 'AUan' // Place the ID Of the Missile Cast Ability
    integer MissileId = 'hfoo' // Place the ID of the Missile Unit
endglobals

// No need to touch this. This is to clear the Missile data when target dies or missile reaches target
function ClearMissile takes unit missile, integer missileId, timer t returns nothing
    call KillUnit(missile) 
    call PauseTimer(t)
    call DestroyTimer(t)
    call FlushChildHashtable(MissileHash, missileId)
endfunction

// These is basically the Missile Movement every 0.03 checking distance between missile and target.
// No damage nor stun has been added. There are comments where Damage and Stun should be, add them yourself.
function MissileTimerFunc takes nothing returns nothing
    local timer t = GetExpiredTimer() // Timer
    local integer i = GetHandleId(t) // Timer ID
    local unit tg = LoadUnitHandle(MissileHash, i, 1) // Target
    local real counter = LoadReal(MissileHash, i, 2)
    local unit u // Missile
    local real facing // Missile Facing
    local real ux // Missile X
    local real uy // Missile Y
    local real tx // Target X
    local real ty // Target Y
    local real x // Offset Required
    local real y // offset Required
    local real dx // Distance Required
    local real dy // Distance Required
    local real accel // Acceleration
    local real angle // Offset Angle
    local real speed // Missile Speed
    local real distance // Distance
    
    if GetWidgetLife(tg) > 0 then // If Target is alive
    
        set u = LoadUnitHandle(MissileHash, i, 0)
        set tx = GetUnitX(tg)
        set ty = GetUnitY(tg)
        set ux = GetUnitX(u)
        set uy = GetUnitY(u)
        set facing = 57.29 * Atan2(ty-uy, tx-ux)
        call SetUnitFacing(u, facing) // Make Missile Face Target
        
        if counter > 2 then // After 2 seconds
            set accel = LoadReal(MissileHash, i, 3) + MissileAcceleration // Increase Acceleration by 0.15 every 0.03 secs.
            call SaveReal(MissileHash, i, 3, accel)
            set speed = MissileSpeed+accel // Speed + Acceleration
            set angle = facing * 0.01745
            set x = ux + speed * Cos(angle)
            set y = uy + speed * Sin(angle)
            call SetUnitX(u, x) // Move Missile Towards Target
            call SetUnitY(u, y) // Move Missile Towards Target
            set dx = tx-x
            set dy = ty-y
            set distance = SquareRoot(dx*dx + dy*dy)
            if distance <= 16 then
                // Stun the Target
                // Deal Damage
                call ClearMissile(u, i, t) 
            endif
        else
            call SaveReal(MissileHash, i, 2, counter + 0.03) // Increase Counter if it's lower than 2
        endif
    else
        call ClearMissile(u, i, t)
    endif
endfunction

// This happens when you cast the ability.
function Trig_MissileCast_Actions takes nothing returns boolean
    local unit u
    local unit m
    local timer t
    local integer i
    local unit tg
    
    if GetSpellAbilityId() == MissileAbilityId then
        set u = GetTriggerUnit()
        set tg = GetSpellTargetUnit()
        set m = CreateUnit(GetTriggerPlayer(), MissileId, GetUnitX(u), GetUnitY(u), 57.29 * Atan2(GetUnitY(tg)-GetUnitY(u), GetUnitX(tg)-GetUnitX(u))) // Missile Creation
        set t = CreateTimer()
        set i = GetHandleId(t)
        
        call SaveUnitHandle(MissileHash, i, 0, m)
        call SaveUnitHandle(MissileHash, i, 1, tg)
        
        call TimerStart(t, 0.03, true, function MissileTimerFunc)
        
        set t = null
        set u = null
        set m = null
    endif    

    return FALSE
endfunction

//===========================================================================
function InitTrig_Missile_Cast takes nothing returns nothing
    set gg_trg_Missile_Cast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Missile_Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Missile_Cast, Condition( function Trig_MissileCast_Actions ) )
endfunction
 
Last edited:
Level 8
Joined
Mar 5, 2011
Messages
199
GUI or JASS?

EDIT: I Hope it's JASS: Take a minute to read all the code, functions, and comments. Try to see the logic in all that stuff, and always feel free to ask anything you want. I tested and works perfectly. It's a bit fast though, thankfully really easy to modify.

JASS:
globals
    hashtable MissileHash = InitHashtable()
    real MissileSpeed = 6 // This is 200 * 0.03
    real MissileAcceleration = 0.15 // This is 5 * 0.03
    integer MissileAbilityId = 'AUan' // Place the ID Of the Missile Cast Ability
    integer MissileId = 'hfoo' // Place the ID of the Missile Unit
endglobals

// No need to touch this. This is to clear the Missile data when target dies or missile reaches target
function ClearMissile takes unit missile, integer missileId, timer t returns nothing
    call KillUnit(missile) 
    call PauseTimer(t)
    call DestroyTimer(t)
    call FlushChildHashtable(MissileHash, missileId)
endfunction

// These is basically the Missile Movement every 0.03 checking distance between missile and target.
// No damage nor stun has been added. There are comments where Damage and Stun should be, add them yourself.
function MissileTimerFunc takes nothing returns nothing
    local timer t = GetExpiredTimer() // Timer
    local integer i = GetHandleId(t) // Timer ID
    local unit tg = LoadUnitHandle(MissileHash, i, 1) // Target
    local real counter = LoadReal(MissileHash, i, 2)
    local unit u // Missile
    local real facing // Missile Facing
    local real ux // Missile X
    local real uy // Missile Y
    local real tx // Target X
    local real ty // Target Y
    local real x // Offset Required
    local real y // offset Required
    local real dx // Distance Required
    local real dy // Distance Required
    local real accel // Acceleration
    local real angle // Offset Angle
    local real speed // Missile Speed
    local real distance // Distance
    
    if GetWidgetLife(tg) > 0 then // If Target is alive
    
        set u = LoadUnitHandle(MissileHash, i, 0)
        set tx = GetUnitX(tg)
        set ty = GetUnitY(tg)
        set ux = GetUnitX(u)
        set uy = GetUnitY(u)
        set facing = 57.29 * Atan2(ty-uy, tx-ux)
        call SetUnitFacing(u, facing) // Make Missile Face Target
        
        if counter > 2 then // After 2 seconds
            set accel = LoadReal(MissileHash, i, 3) + MissileAcceleration // Increase Acceleration by 0.15 every 0.03 secs.
            call SaveReal(MissileHash, i, 3, accel)
            set speed = MissileSpeed+accel // Speed + Acceleration
            set angle = facing * 0.01745
            set x = ux + speed * Cos(angle)
            set y = uy + speed * Sin(angle)
            call SetUnitX(u, x) // Move Missile Towards Target
            call SetUnitY(u, y) // Move Missile Towards Target
            set dx = tx-x
            set dy = ty-y
            set distance = SquareRoot(dx*dx + dy*dy)
            if distance <= 16 then
                // Stun the Target
                // Deal Damage
                call ClearMissile(u, i, t) 
            endif
        else
            call SaveReal(MissileHash, i, 2, counter + 0.03) // Increase Counter if it's lower than 2
        endif
    else
        call ClearMissile(u, i, t)
    endif
endfunction

// This happens when you cast the ability.
function Trig_MissileCast_Actions takes nothing returns boolean
    local unit u
    local unit m
    local timer t
    local integer i
    local unit tg
    
    if GetSpellAbilityId() == MissileAbilityId then
        set u = GetTriggerUnit()
        set tg = GetSpellTargetUnit()
        set m = CreateUnit(GetTriggerPlayer(), MissileId, GetUnitX(u), GetUnitY(u), 57.29 * Atan2(GetUnitY(tg)-GetUnitY(u), GetUnitX(tg)-GetUnitX(u))) // Missile Creation
        set t = CreateTimer()
        set i = GetHandleId(t)
        
        call SaveUnitHandle(MissileHash, i, 0, m)
        call SaveUnitHandle(MissileHash, i, 1, tg)
        
        call TimerStart(t, 0.03, true, function MissileTimerFunc)
        
        set t = null
        set u = null
        set m = null
    endif    

    return FALSE
endfunction

//===========================================================================
function InitTrig_Missile_Cast takes nothing returns nothing
    set gg_trg_Missile_Cast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Missile_Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Missile_Cast, Condition( function Trig_MissileCast_Actions ) )
endfunction


I'm sorry but I don't know Jass. :(
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Do the following:
1- Create a Trigger
2- Go to Edit -> Convert to Custom Text
3- Delete everything inside
4- Paste this script I gave you.
5- Rename the trigger to whatever you want.
6- Replace these 2 with your own. To know the ID of a unit/ability go to the Object Editor and press CTRL+D. 'AUan' is Animate Dead, and 'hfoo' is Footman.
JASS:
    integer MissileAbilityId = 'AUan' // Place the ID Of the Missile Cast Ability
    integer MissileId = 'hfoo' // Place the ID of the Missile Unit

That's all.

The damage and stun part is left to add. You can tell me how do you want those to work and i'll add them to the code.

In any case, the Damage/stun goes where it's indicated
JASS:
...
            if distance <= 16 then
                // Stun the Target
                // Deal Damage
                call ClearMissile(u, i, t) 
            endif
...

You need JNPG for this. It's on my signature.
 
Level 8
Joined
Mar 5, 2011
Messages
199
Do the following:
1- Create a Trigger
2- Go to Edit -> Convert to Custom Text
3- Delete everything inside
4- Paste this script I gave you.
5- Rename the trigger to whatever you want.
6- Replace these 2 with your own. To know the ID of a unit/ability go to the Object Editor and press CTRL+D. 'AUan' is Animate Dead, and 'hfoo' is Footman.
JASS:
    integer MissileAbilityId = 'AUan' // Place the ID Of the Missile Cast Ability
    integer MissileId = 'hfoo' // Place the ID of the Missile Unit

That's all.

The damage and stun part is left to add. You can tell me how do you want those to work and i'll add them to the code.

In any case, the Damage/stun goes where it's indicated
JASS:
...
            if distance <= 16 then
                // Stun the Target
                // Deal Damage
                call ClearMissile(u, i, t) 
            endif
...

You need JNPG for this. It's on my signature.


Nice. Thanks man :)
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
well yea I agree on that, even if unit is dead it never hearts to damage him some more eh :D and if the call is slower, then overall the >= check is faster, because it will sometimes evaluate to true and running for dead units, but most likely it wont run so many times that the IsUnitType check would outperform it
 
Status
Not open for further replies.
Top