[solved] Knockback 2024

Rheiko

Spell Reviewer
Level 25
Joined
Aug 27, 2013
Messages
4,126
Since you don't use GUI, would you prefer to use JASS or LUA then?
GUI is like the simplest if you want to start learning how to do it.

Or if you don't want to trouble yourself, you can use GUI Knockback 2.5D v4.2.5.0
But you have to replace the UnitIndexer trigger which is included there (but is outdated) with the newer one - GUI Unit Indexer 1.4.0.0 before you can use the knockback system, otherwise it won't work properly in the recent version of the game.
 

Rheiko

Spell Reviewer
Level 25
Joined
Aug 27, 2013
Messages
4,126
To import it, you literally just have to copy and paste the required triggers and they are already bundled in the same folder.
To use it, you just need to run the trigger after registering the unit you want to knockback, the angle for the knockback, the distance you prefer, and the time duration of the knockback. It's much simpler than it looks like.

But if you really prefer to create a knockback by yourself, it's just moving a unit to a certain distance in a certain direction for every certain interval.
JASS:
// you need to assign a timer to this function, usually 0.03125 is smooth enough
function knockback takes nothing returns nothing
   // set up local variables
   local real x1
   local real y1
   local real x2
   local real y2
   local real x3
   local real y3
   local real distance
   local real angle
   local unit YourTarget
   local unit KnockbackSource

   // get the current coord of the units
   set x1 = GetUnitX(YourTarget)
   set y1 = GetUnitY(YourTarget)

   set x2 = GetUnitX(KnockbackSource)
   set y2 = GetUnitY(KnockbackSource)
 
   // get the angle from source of knockback to target
   set angle = bj_RADTODEG * Atan2(y1-y2, x1-x2)

   // calculate the new coordinate
   set x3 = x1 + distance * Cos(angle * bj_DEGTORAD)
   set y3 = y1 + distance * Sin(angle * bj_DEGTORAD)

   // move the unit to the new coord
   call SetUnitX(YourTarget, x3)
   call SetUnitY(YourTarget, y3)
endfunction
this just handles the knockback movement, you still have to adjust the code to handle when to start and when to stop. Otherwise, your unit can get out of the map border and cause a crash.
 
Last edited:
This library is more powerful, has no dependencies and has a clear jass API
 
Top