• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Missile Manual

Level 19
Joined
Mar 18, 2012
Messages
1,716

Missile Manual - Collision Types v.1.4.2


[self=https://www.hiveworkshop.com/forums/jass-resources-412/missile-265370/]Back to the Missile main thread[/self]

First of all let's see which collision parameters you can set for a missile instance.
The following table gives us a good overview.

Missile's collision membersDescription
real collision
This member is the collision for missiles in x/y plane.
real collisionZ
This member is the collision for missiles in z-axis.


Unit collision

One of the core features of a missile is the detection of units in collision size.

Missile API for units:
JASS:
//  Core API:
//  ¯¯¯¯¯¯¯¯¯
      static method onCollide takes Missile missile, unit hit returns boolean
//          • Runs for units, which are in collision size.
//          • Grants full access to all missile fields via "Missile missile" argument.

//  Special API:
//  ¯¯¯¯¯¯¯¯¯¯¯¯
//  A missile remembers a unit handle in its memory
//  after passing it to method onCollide.
//  By default a second collision event is no longer possible.
//  
       readonly group unitsHit 
//          • Stores all units, which run through method onCollide.
//          • ClearGroup flushes the entire memory of hit units for this missile instance.
//          • GroupRemoveUnit removes a desired unit from the memory of hit units for this missile instance.
Demo Code:
JASS:
    private struct Example extends array
    
        // Runs on unit collision for missiles launched in this struct. ( mandatory )
        private static method onCollide takes Missile missile, unit hit returns boolean
            // Simply read the assigned missile members like source, owner or damage.
            if UnitAlive(hit) and IsUnitEnemy(hit, missile.owner) then 
                call UnitDamageTarget(missile.source, hit, missile.damage, false, false, null, null, null)
                // Read this missile's current position via missile.x and missile.y
                call DestroyEffect(AddSpecialEffect("Abilities\Weapons\PhoenixMissile\Phoenix_Missile_mini.mdl", missile.x, missile.y))
            endif
            return true// Determines the future of this missile. "true" will destroy the instance.
        endmethod
        
        // implement "MissileStruct" enables Missile behaviours for this struct. 
        implement MissileStruct
    endstruct

Destructable collision

Similar to other widgets a missile can detect a collision with a destructable.
Enable destructable detection by setting Missile_USE_DESTRUCTABLE_FILTER in the global setup of library Missile to true.

Missile API for destructables:
JASS:
//  Core API:
//  ¯¯¯¯¯¯¯¯¯
      static method onDestructable takes Missile missile, destructable hit returns boolean
//          • Runs after onDestructableFilter ( if a filter is declared )
//          • Runs for destructables, which are in collision size.
//          • Grants full access to all missile fields via "Missile missile" argument.

      static method onDestructableFilter takes nothing returns boolean // ( optional )
//          • Runs before onDestructable.
//          • Runs for destructables within collision size + Missile_MAX_COLLISION_RANGE.
//          • Get the filter destructable via "GetFilterDestructable()" 
//          • Designed only for improving code read-ability.

//  Special API:
//  ¯¯¯¯¯¯¯¯¯¯¯¯
//  A missile remembers a destructable handle in its memory
//  after passing it to method onDestructable.
//  By default a second collision event is no longer possible.
//  
       missile.flushWidgetsHit(destructable) 
//          - Clears the entire memory of hit widgets for this missile instance.
       missile.removeWidgetHit(destructable)
//          - Removes a desired widget from the memory of hit widgets for this missile instance.
Demo code:
JASS:
    private struct Example extends array
        
        // Runs before onDestructable. ( optional )
        // Good for read-ability, but slows down the operation.
        // For best speed results, use IsDestructableTree directly in onDestructable.
        private static method onDestructableFilter takes nothing returns boolean
            return IsDestructableTree(GetFilterDestructable())
        endmethod
    
        // Runs on destructable collision. ( mandatory )
        private static method onDestructable takes Missile missile, destructable hit returns boolean
            call SetDestructableAnimation(hit, "stand hit")
            
            call missile.removeWidgetHit(hit)// Allows this missile to collide again with destructable "hit".
            return false
        endmethod
        
        // implement "MissileStruct" enables Missile behaviours for this struct. 
        implement MissileStruct
    endstruct

Item collision

Similar to other widgets a missile can detect a collision with an item.
Enable item detection by setting Missile_USE_ITEM_FILTER in the global setup of library Missile to true.

Missile API for item:
JASS:
//  Core API:
//  ¯¯¯¯¯¯¯¯¯
      static method onItem takes Missile missile, item hit returns boolean
//          • Runs after onItemFilter ( if a filter is declared )
//          • Runs for items, which are in collision size.
//          • Grants full access to all missile fields via "Missile missile" argument.

      static method onItemFilter takes nothing returns boolean // ( optional )
//          • Runs before onItem.
//          • Runs for items within collision size + Missile_MAX_COLLISION_RANGE.
//          • Get the filter item via "GetFilterItem()" 
//          • Designed only for improving code read-ability.

//  Special API:
//  ¯¯¯¯¯¯¯¯¯¯¯¯
//  A missile remembers ab item handle in its memory
//  after passing it to method onItem.
//  By default a second collision event is no longer possible.
//  
       missile.flushWidgetsHit(item) 
//          - Clears the entire memory of hit widgets for this missile instance.
       missile.removeWidgetHit(item)
//          - Removes a desired widget from the memory of hit widgets for this missile instance.
Demo code:
JASS:
    private struct Example extends array
        
        // Runs before onItem. ( optional )
        // Good for read-ability, but slows down the operation.
        private static method onItemFilter takes nothing returns boolean
            return IsItemVisible(GetFilterItem())
        endmethod
    
        // Runs on item collision. ( mandatory )
        private static method onItem takes Missile missile, item hit returns boolean
            call SetItemCharges(hit, 2)
            
            call missile.removeWidgetHit(hit)// Allows this missile to collide again with item "hit".
            return false
        endmethod
        
        // implement "MissileStruct" enables Missile behaviours for this struct. 
        implement MissileStruct
    endstruct

Collision in z-axis

By default library Missile doesn't check for z parameters when it comes to unit collisions.
If a unit is in collision size x/y onCollide runs, irrespective of having a flying or on lower terrain standing target.
Enable z-axis collision checks by setting Missile_USE_COLLISION_Z_FILTER in library Missile to true.

Furthermore you have to set a fictional value for a units body size. ( also in the library Missile setup )
JASS:
    function GetUnitBodySize takes unit whichUnit returns real
        return 100. // LoadReal(hash, GetUnitTypeId(whichUnit), KEY_UNIT_BODY_SIZE)<- Example
    endfunction

Z-axis collision detection adds a small amount of overhead, thus beeing an optional toogle.
Other widgets like destructables always evaluate a z-axis detection no matter how you setup Missile.

To alter the body size of a destructable this function is part of the global Missile setup.
JASS:
    function GetDestructableHeight takes destructable d returns real
        return GetDestructableOccluderHeight(d)
    endfunction

Limitations:
  • Destructables placed or created with an z-offset can't be detected properly
Last edited:
Back
Top