Sharing Projectile Impact Trigger

Edward

New Member
Reaction score
2
EDIT: This Trigger (co-dependent triggers) has/have been optimized for memory performance.

This trigger is meant to make an explosion (import the explosion model of your choice) when a projectile lands at its target. There are two versions. One for if the target is attacked, but does not die. The other is for if the target actually does die. Explanation of the triggers are given below.
Trigger:
  • DistanceVelocity Trigger
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Cannon
    • Actions
      • Set DistanceX1 = (X of (Position of (Attacking unit)))
      • Set DistanceY1 = (Y of (Position of (Attacking unit)))
      • Set DistanceX2 = (X of (Position of (Attacked unit)))
      • Set DistanceY2 = (Y of (Position of (Attacked unit)))
      • Set DistanceX = (Power((DistanceX1 - DistanceX2), 2.00))
      • Set DistanceY = (Power((DistanceY1 - DistanceY2), 2.00))
      • Set DistanceTotal = (Square root((DistanceX + DistanceY)))
      • Wait ((DistanceTotal / 3500.00) + 0.50) game-time seconds
      • Set CannonSmoke = (Position of (Attacked unit))
      • Unit - Create 1 Emissary for Neutral Passive at CannonSmoke facing CannonSmoke
      • Unit Group - Add (Last created unit) to DeleteGroup
      • Custom script: call RemoveLocation (udg_CannonSmoke)


Trigger:
  • Projectile Impact Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Killing unit)) Equal to Cannon
    • Actions
      • Set CannonSmoke = (Position of (Dying unit))
      • Set UnitRemoveShit = (Dying unit)
      • Unit - Create 1 Emissary for Neutral Passive at CannonSmoke facing CannonSmoke
      • Unit Group - Add (Last created unit) to DeleteGroup
      • Custom script: call RemoveLocation (udg_CannonSmoke)
      • Trigger - Run Distance for dies On <gen> (ignoring conditions)
      • Trigger - Turn off (This trigger)


Trigger:
  • Projectile Impact On
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Killing unit)) Equal to Cannon
    • Actions
      • Wait 1.00 game-time seconds
      • Trigger - Turn on Projectile Impact Dies <gen>
      • Trigger - Turn off (This trigger)


Trigger:
  • DeleteUnits
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in DeleteGroup and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
          • Unit Group - Remove (Picked unit) from DeleteGroup


In the first trigger, the trigger is started EXACTLY when the cannon is given the order to attack another unit. This means we need to time when the smoke appears upon the attacked target's location. This means we need to determine the time it takes for the projectile to arrive at the target from the time that the projectile is released.

To do this we need the distance between the cannon and the target, call this D. We also need the velocity of the projectile, call this V. We also need the time it takes for the cannon to release the projectile, call this B.

The time it takes for the projectile to travel the distance D is given by D/V. For instance, if you are traveling 60mph, it takes 0.5 hours to travel 30 miles, because 30 miles divided by 60 miles/hour = 0.5 hours or 30 minutes.

So it would seem that the smoke should appear at our target at exactly D/V seconds upon whence the order is given to attack. However the EXACT time that the order is given to attack, is not the same when the projectile is released.

Say that the projectile takes 10 seconds to be released from the time that the unit is ordered to attack. Let the distance = 1000units and velocity = 1000units/sec. The using the formula D/V the smoke will appear on our target 1 second after the order is given. Wait a second, the projectile itself hasn't even been released! In fact it won't be released for another 9 seconds, and then it still needs another 1 second to travel to the target!

Our formula now looks like this.
D/V + B.

The value of B comes from the Object Editor under Combat-Attack 1-Animation Back-swing Point. This is the time that the projectile is released from when the order is given.

The value of V also comes from the Object Editor under Combat - Attack 1 - Projectile Speed

The value of D is obtained by the Distance Formula. This is given by ((x1 - x2)^2 + (y1 - y2)^2)^(1/2) or (x position of cannon minus x position of target) squared added to (y position of cannon minus y position of target) squared. Then take the square root of that entire value.

Another way to obtain D is to set some REAL = Distance between points A and B. However this seems to bug and/or cause lag on occasion. Using the "distance formula" above is memory efficient and perfect, you can also adjust the distance formula for the projectile arc caused by gravity, where the in-game function cannot be adjusted. Also the in-game function cannot be adjusted for distances in 3-D. You would add (z1 - z2)^2 before taking the square root. Knowledge of the 2-D and 3-D distance functions will also be critical in Starcraft II's GE.

For the Second Trigger:
You do not need to know the distance between the targets here. This is because the trigger fires EXACTLY when the target dies, thus the smoke will appear precisely when the projectile hits.

However there is a problem with this. If multiple units are killed, the the smoke will appear multiple times where those units were killed. What we need to do here is TURN THIS TRIGGER OFF after one of the units die. However, before turning it off, we need to RUN a secondary trigger that will TURN ON our original trigger after 3 seconds (or any value that you want, I personally used 1 second). This secondary trigger must also turn itself off after being used. This secondary trigger should be OFF initially. Notice the difference between RUN and TURN ON. Running the trigger fires it, turn it on simply means it will fire when the outside event occurs.

The Fourth Trigger:
This trigger is critical. It removes all of the dummy units created for the smoke effects every 5 seconds (this can be adjusted to your preference). Notice in each trigger we add created units to a "deletion group;" this is the trigger that deletes them. Also, DO NOT ADD A CUSTOM SCRIPT to the fourth trigger to destroy the group, you'll stop it from working. The size of this group is already regulated by removing the units from the unit-group.

There are many ways to modify the fourth and expand upon it to make sure your smoke doesn't disappear earlier in its lifespan than others, however this involves some heavy modular arithmetic and Boolean "is an Integer" comparisons in the first 3 triggers in respect to when the smoke is created in game-time. If anyone needs this, I'll create it for you.
 

Edward

New Member
Reaction score
2
I've discovered through testing that the first trigger only works if the Projectile Arc = 0 radians.

In order to get the length of the path of the arc you'll need to use second-year calculus, as the path of the arc is simulated by gravity at 9.8m/s^2. I will keep this thread open in my favorites menu for now in case anyone needs me to crunch the numbers (variables) for the arc length of the curve.

If the projectile is moving fast enough (faster than 2000) at a low arc (less than 30 degrees), this won't be noticeable unless it travels an extremely long distance (less than 3000 units). However most projectiles do not usually meet all 3 conditions simultaneously.

I also added "Grape Shot" spells to the cannons, releasing a deadly cone of fire and ashes in front of them.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top