- Joined
- Dec 6, 2007
- Messages
- 233
I'm designing a framework for a projectile system for a summer project I'm working on. I condensed a large number of small triggers into one huge one to reduce lag, so I'm only going to show an excerpt.
This part of the trigger involves registering if a projectile hits a unit, then calculating where the damage goes. The first issue is that in the latter half of the trigger, I need to reference a hashtable value via a unit handle. However, i cannot simply use "picked unit". So i used a handle variable. I couldn't find a direct way to save a handle to the variable, so i saved "picked unit" to the handle variable (Ship_Handle). Can this be done? Will it work?
Secondly, the trigger never registers a hit. I see no reason why it shouldn't, so that's why I've come here. Let me explain what's going on here:
I draw two circular regions. One around the projectile, and one around the ship. Both regions make up the "size" of their respective object. If the regions overlap, then the objects have collided, and it registers a hit. If a hit is registered, it clacluated damage to armor, then if the armor is gone, it damages the ship. This line of code is what I use to check for overlap:
Justification: Everything has a size. The bigger the size, the easier it is to hit something with it! It also helps for if you have a massive ship, but the hitbox is still so small that the projectile can go straight through without "hitting".
If anyone has a solution to either issues, help would be greatly appreciated.
-
Unit Group - Pick every unit in Temp_Unit_Group and do (Actions)
-
Loop - Actions
-
Set Ship = (Picked unit)
-
Set Ship_Handle = (Picked unit)
-
Set Temp_Unit_Loc = (Position of (Picked unit))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Unit-type of (Picked unit)) Equal to Frigate
-
-
Then - Actions
-
Set Physical_Radius = 100.00
-
-
Else - Actions
-
-
Set Temp_Unit_Group2 = (Units in (Playable map area) matching (((Matching unit) is A sapper) Equal to True))
-
Unit Group - Pick every unit in Temp_Unit_Group2 and do (Actions)
-
Loop - Actions
-
Set Projectile = (Picked unit)
-
Set Temp_Unit_Loc2 = (Position of (Picked unit))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
((Distance between Temp_Unit_Loc and Temp_Unit_Loc2) - (Load Projectile_Hitbox of (Key (Picked unit)) from Projectile_Hash)) Less than or equal to Physical_Radius
-
((Picked unit) is alive) Equal to True
-
-
Then - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Load (Key armorvalue) of (Key Ship_Handle) from armorhash) Greater than or equal to (Load Projectile_Damage of (Key (Picked unit)) from Projectile_Hash)
-
-
Then - Actions
-
Hashtable - Save ((Load (Key armorvalue) of (Key Ship_Handle) from armorhash) - (Load Projectile_Damage of (Key (Picked unit)) from Projectile_Hash)) as (Key armorvalue) of (Key Ship_Handle) in armorhash
-
-
Else - Actions
-
Unit - Cause Missile_Unit to damage Ship, dealing ((Real((Load Projectile_Damage of (Key (Picked unit)) from Projectile_Hash))) - (Real((Load (Key armorvalue) of (Key Ship_Handle) from armorhash)))) damage of attack type Spells and damage type Normal
-
Hashtable - Save 0 as (Key armorvalue) of (Key Ship_Handle) in armorhash
-
-
-
Unit - Kill (Picked unit)
-
-
Else - Actions
-
-
Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
-
Custom script: call RemoveLocation(udg_Temp_Unit_Loc2)
-
Custom script: call DestroyGroup(udg_Temp_Unit_Group)
-
Custom script: call DestroyGroup(udg_Temp_Unit_Group2)
-
-
-
-
Secondly, the trigger never registers a hit. I see no reason why it shouldn't, so that's why I've come here. Let me explain what's going on here:
I draw two circular regions. One around the projectile, and one around the ship. Both regions make up the "size" of their respective object. If the regions overlap, then the objects have collided, and it registers a hit. If a hit is registered, it clacluated damage to armor, then if the armor is gone, it damages the ship. This line of code is what I use to check for overlap:
-
((Distance between Temp_Unit_Loc and Temp_Unit_Loc2) - (Load Projectile_Hitbox of (Key (Picked unit)) from Projectile_Hash)) Less than or equal to Physical_Radius
If anyone has a solution to either issues, help would be greatly appreciated.