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

[Trigger] Detecting When Two Units Collide

Status
Not open for further replies.
Level 12
Joined
Jun 28, 2008
Messages
688
I need to know how to detect a collision between two units. My hero throws a spear (the spear being an unselectable, hovering unit) and I have triggers all set up so that the spear moves forward and falls slightly until it hits the ground at which point it dies.

What I need to know is how to detect when the spear collides with another unit so that I can kill the spear and cause damage to the receiving unit.
 
Level 15
Joined
Dec 18, 2007
Messages
1,098
Erm, if you add an event each time you use the spell, it will start to lag after a few casts. I believe you triggered the movement of the spear, if so, then I suggest you pick every unit around the spear which belongs to an enemy player of the owner of the spear and if there are units in the group, add a if-then-else. If- [The Spear] is alive equals to true. Then- Deal damage. Kill spear. Else do nothing.
Why If-Then-Else? To avoid the spear damaging more than 1 unit.
 
Level 21
Joined
Aug 9, 2006
Messages
2,384
If you use GUI, then it starts to lag after a while, with JASS you can simply destroy the trigger at the end, for GUI i would recommend that you use a pick every unit in range with condition use and add them to a group, detect all units which are enemies etc and which are in 25 diameter around the spear, if theres a single unit in the group, take that unit, damage it and destroy the spear.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Do not destroy the trigger every cast. Trigger destruction results in a cause of possiable map crashes due to a hande allocation error. You can destroy them ut it is recomended you do so as little as possiable to reduce chance of map crashing. After every 20-40 events added and no longer needed is probably a good time.

This is what Captian Griffien says but it does explain a lot about random map crashes.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You could of course use an array of all collisionable units like we do this days with structs.

Just run a periodic timer (I heard Poot say once that Periodic events are shit, I believe him) with, say, 0.035 time till it calls the callback function (I believe it calls a trigger with GUI? never really used timers with GUI), there you loop between all the collisionable units.
You will determine what's the number of units by adding or decreasing an integer when a collisionable unit is created or dies respectively.

I assume this is the most efficient and also easiest way to do this.
 
Level 12
Joined
Jun 28, 2008
Messages
688
Could I use the "Reset Trigger" action in a seperate trigger to remove the event each time the damage is dealt, thus preventing a pileup of events?

EDIT: Here's what I have so far, let me know if this works well enough to not lag the map.

  • GenericSpear
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Generic Spear
    • Actions
      • Set SpearThrower = (Casting unit)
      • Set TempPoint = (Position of SpearThrower)
      • Set TempPoint2 = (TempPoint offset by 40.00 towards ((Facing of SpearThrower) - 40.00) degrees)
      • Unit - Create 1 Generic Spear for (Owner of SpearThrower) at TempPoint2 facing (Facing of SpearThrower) degrees
      • Set TempSpear = (Last created unit)
      • Trigger - Add to SpearDamage <gen> the event (Unit - A unit comes within 50.00 of TempSpear)
      • Unit - Add a 2.00 second Generic expiration timer to TempSpear
      • Set SpearN = 0.00
      • Trigger - Turn on SpearMove <gen>
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_TempPoint2)
      • Custom script: call RemoveLocation(udg_TempPoint3)
  • SpearMove
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • Set SpearPos = (Position of TempSpear)
      • Set SpearMove = (SpearPos offset by (((Real((Strength of SpearThrower (Include bonuses)))) x 0.14) + 10.00) towards (Facing of TempSpear) degrees)
      • Set SpearN = (SpearN + (((Real((Strength of SpearThrower (Include bonuses)))) x 0.14) + 10.00))
      • Unit - Move TempSpear instantly to SpearMove
      • Animation - Change TempSpear flying height to -20.00 at 3.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • SpearN Greater than or equal to ((Real((Strength of SpearThrower (Include bonuses)))) x 60.00)
              • (Current flying height of TempSpear) Less than or equal to 0.00
        • Then - Actions
          • Unit - Kill TempSpear
          • -------- This is where the SpearDamage trigger is reset to remove the event, does this work? --------
          • Trigger - Reset SpearDamage <gen>
          • Custom script: call RemoveLocation(udg_SpearPos)
          • Custom script: call RemoveLocation(udg_SpearMove)
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Do nothing
  • SpearDamage
    • Events
    • Conditions
    • Actions
      • Unit - Cause SpearThrower to damage (Triggering unit), dealing ((Real((Strength of SpearThrower (Include bonuses)))) x ((Real((Level of Generic Spear for SpearThrower))) x 0.50)) damage of attack type Chaos and damage type Normal
      • Unit - Kill TempSpear
      • Special Effect - Create a special effect attached to the chest of (Triggering unit) using Objects\Spawnmodels\Critters\Albatross\CritterBloodAlbatross.mdl
      • Special Effect - Destroy (Last created special effect)
 
Last edited:
Status
Not open for further replies.
Top