Difference between revisions of "Collision Detection"

From HIVE
Jump to navigation Jump to search
(created on request)
 
(and of course I forgot categories)
Line 16: Line 16:
  
 
==Data editor method==
 
==Data editor method==
Other, much faster method is using in-built search effects. They are faster then the trigger method, because the engine already contains some optimalization. Basically what you need to do is create a buff that periodically launches a search effect. The search effect will have a radius of 0, "Extend by unit radius" and launches a dummy damage effect. This will create an universal buff that can be applied to any unit, to include it into collision detection. This method works fine for ~500 units (no FPS drop on 4 cores, 2.8 MHz).
+
Other, much faster method is using in-built search effects. They are faster then the trigger method, because the engine already contains some optimalization. Basically what you need to do is create a buff that periodically launches a search effect. The search effect will have a radius of 0, "Extend by unit radius" and launches a dummy damage effect. The dummy effect is then hooked onto a trigger. This will create an universal buff that can be applied to any unit, to include it into collision detection. This method works fine for ~500 units (no FPS drop on 4 cores, 2.8 MHz).
 +
 
 +
[[Category:StarCraft II]][[Category:Triggers]][[Category:Tutorials]]

Revision as of 17:51, 20 August 2011

Collision Detection is a technique to decide when two objects (in SC2 most propably units) occupy the same space, which can be used for example by physics engines. There are several methods, if you know any other, please add it here.

Simple trigger method

This method simply compares all units to each other and calculates their distances. Works fine for ~200 units (no FPS drop on 4 cores, 2.8 MHz).

lv_unitGroup = (All units); //group of units tested for collision between each other

//we go through all units and compare them to all units with higher ID in group (if we compared each unit to each other, we would calculate each PAIR twice)
for( I from 0 tp (Count units in lv_unitGroup)-1 )
    for (J from I+1 to (Count units in lv_unitGroup) )
        x1, y1 = X and Y of (position of (unit I from lv_unitGroup ))
        x2, y2 = X and Y of (position of (unit J from lv_unitGroup ))
        // r1, r2 are radiuses of the two units
        if( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < (r1+r2)*(r1+r2) )
                COLLISSION( unit I, unit J)

Data editor method

Other, much faster method is using in-built search effects. They are faster then the trigger method, because the engine already contains some optimalization. Basically what you need to do is create a buff that periodically launches a search effect. The search effect will have a radius of 0, "Extend by unit radius" and launches a dummy damage effect. The dummy effect is then hooked onto a trigger. This will create an universal buff that can be applied to any unit, to include it into collision detection. This method works fine for ~500 units (no FPS drop on 4 cores, 2.8 MHz).