Moving missile with partial homing

kingkwong92

Well-Known Member
Reaction score
25
I'm having trouble making my missile have partial homing. My missile is a unit with 1 move speed and 3.0 turn rate. It has a global acquisition range. When cast it turns towards the nearest enemy target. I want to change the direction of the of the missile towards the direction of the facing angle of the missile. I don't want it to turn if the angle is greater than 90 degrees from its original path (easier it current path). However I cannot get the conditions right. Please help, this is the main part that I need help with:

((Facing of (Picked unit)) + missile_angle) Less than or equal to 90.00
((Facing of (Picked unit)) + missile_angle) Greater than or equal to 270.00

Also is it possible to detect which unit is targeted by the missile. If possible, I would like to add:
if distance between user and missile is greater than distance between user and target.
This prevents the missile homing on the target if it has already passed it.
Thanks

Trigger:
  • Movement
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in missile_group) Greater than 0
        • Then - Actions
          • Unit Group - Pick every unit in missile_group and do (Actions)
            • Loop - Actions
              • Set Player_Number = (Player number of (Owner of (Picked unit)))
              • Set missile = (Picked unit)
              • Set player_number = (Player number of (Owner of (Picked unit)))
              • Set missile_handle = (Picked unit)
              • Set missile_speed = (Load 1 of (Key missile_handle) from missile_hash)
              • Set missile_range = (Load 2 of (Key missile_handle) from missile_hash)
              • Set missile_damage = (Load 3 of (Key missile_handle) from missile_hash)
              • Set missile_hits = (Load 4 of (Key missile_handle) from missile_hash)
              • Set missile_user = (Load 5 of (Key missile_handle) in missile_hash)
              • Set missile_distance = (Load 6 of (Key missile_handle) from missile_hash)
              • Set missile_angle = (Load 7 of (Key missile_handle) from missile_hash)
              • Set missile_point_1 = (Position of missile)
              • Set missile_point_2 = (missile_point_1 offset by missile_speed towards missile_angle degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain pathing at missile_point_2 of type Flyability is off) Equal to True
                • Then - Actions
                  • Custom script: call RemoveLocation(udg_missile_point_2)
                  • Set missile_point_2 = missile_point_1
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • missile_hits Greater than 0
                  • missile_distance Greater than 0.00
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of missile) Equal to Shuriken
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • missile_distance Less than or equal to 1700.00
                          • missile_distance Greater than or equal to 500.00
                          • ((Facing of (Picked unit)) + missile_angle) Less than or equal to 90.00
                          • ((Facing of (Picked unit)) + missile_angle) Greater than or equal to 270.00
                        • Then - Actions
                          • Game - Display to (All players) for 0.10 seconds the text: Turn
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Facing of (Picked unit)) - missile_angle) Greater than or equal to 270.00
                            • Then - Actions
                              • Set missile_angle = (missile_angle - 1.00)
                            • Else - Actions
                              • Set missile_angle = (missile_angle + 1.00)
                        • Else - Actions
                      • Hashtable - Save missile_angle as 7 of (Key missile_handle) in missile_hash
                      • Custom script: call DestroyGroup(udg_missile_target_group)
                      • Set missile_target_group = (Units within missile_range of missile_point_2 matching (((Matching unit) Not equal to missile_user) and (((Matching unit) is alive) Equal to True)))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in missile_target_group) Greater than 0
                        • Then - Actions
                          • Set missile_target = (Random unit from missile_target_group)
                          • Unit - Cause Hero[player_number] to damage missile_target, dealing missile_damage damage of attack type Pierce and damage type Normal
                          • Set Temp_Loc_1 = (Position of missile_target)
                          • Unit - Create 1 Dummy for (Player(Player_Number)) at missile_point_1 facing missile_point_2
                          • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                          • Unit - Add Stun (dummy) to (Last created unit)
                          • Unit - Set level of Stun (dummy) for (Last created unit) to 1
                          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt missile_target
                          • Set missile_hits = (missile_hits - 1)
                          • Hashtable - Save missile_hits as 4 of (Key missile_handle) in missile_hash
                        • Else - Actions
                          • Set X = (X of missile_point_2)
                          • Set Y = (Y of missile_point_2)
                          • Set missile_distance = (missile_distance - missile_speed)
                          • Hashtable - Save missile_distance as 6 of (Key missile_handle) in missile_hash
                          • Custom script: call SetUnitX(udg_missile,udg_X)
                          • Custom script: call SetUnitY(udg_missile,udg_Y)
                    • Else - Actions
                • Else - Actions
              • Custom script: call RemoveLocation(udg_missile_point_1)
              • Custom script: call RemoveLocation(udg_missile_point_2)
        • Else - Actions
          • Trigger - Turn off (This trigger)
 

kingkwong92

Well-Known Member
Reaction score
25
The fired unit is a sliding unit
It has a global acquisition range and therefore will target thee closest unit.
I plan on adding in a stop command so it will constantly refresh the closest target enemy.
I found that the problem lies with the angles in the condition.
The change from 359.999 degrees to 0 degrees.
E.g degrees (300 + 90) = 30 degrees
real (300 + 90) = 390
So far I did this but it still doesnt work
Set X = (missile_angle + 90.00) Set Y = (missile_angle - 90.00) If (X Greater than or equal to 360.00) then do (Set X = (X - 360.00)) else do (Do nothing) If (Y Less than or equal to 0.00) then do (Set Y = (Y + 360.00)) else do (Do nothing) If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - (Facing of (Picked unit)) Less than or equal to X (Facing of (Picked unit)) Greater than or equal to Y
 

kingkwong92

Well-Known Member
Reaction score
25
Trigger:
  • Movement
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Set X = (missile_angle + 90.00)
      • Set Y = (missile_angle - 90.00)
      • If (X Greater than or equal to 360.00) then do (Set X = (X - 360.00)) else do (Do nothing)
      • If (Y Less than or equal to 0.00) then do (Set Y = (Y + 360.00)) else do (Do nothing)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • missile_distance Less than or equal to 1700.00
          • missile_distance Greater than or equal to 500.00
          • (Facing of (Picked unit)) Less than or equal to X
          • (Facing of (Picked unit)) Greater than or equal to Y
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else)
 

Slapshot136

Divide et impera
Reaction score
471
Trigger:
  • (Facing of (Picked unit)) Less than or equal to X
    • (Facing of (Picked unit)) Greater than or equal to Y

there is no picked unit here - and I don't quite understand your X/Y setup - where is the target? why not just adjust the current angle towards the target? what do you expect the missile to do if there is no target, go straight?
 

kingkwong92

Well-Known Member
Reaction score
25
Thats not the whole trigger. I have a picked unit.
I want to adjust the current angle towards the target however I can't seem to get the conditions right. If there is no target then it will continue going straight
Here is the full trigger. Its really big tho.
Trigger:
  • Movement
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in missile_group) Greater than 0
        • Then - Actions
          • Unit Group - Pick every unit in missile_group and do (Actions)
            • Loop - Actions
              • Set Player_Number = (Player number of (Owner of (Picked unit)))
              • Set missile = (Picked unit)
              • Set player_number = (Player number of (Owner of (Picked unit)))
              • Set missile_handle = (Picked unit)
              • Set missile_speed = (Load 1 of (Key missile_handle) from missile_hash)
              • Set missile_range = (Load 2 of (Key missile_handle) from missile_hash)
              • Set missile_damage = (Load 3 of (Key missile_handle) from missile_hash)
              • Set missile_hits = (Load 4 of (Key missile_handle) from missile_hash)
              • Set missile_user = (Load 5 of (Key missile_handle) in missile_hash)
              • Set missile_distance = (Load 6 of (Key missile_handle) from missile_hash)
              • Set missile_angle = (Load 7 of (Key missile_handle) from missile_hash)
              • Set missile_point_1 = (Position of missile)
              • Set missile_point_2 = (missile_point_1 offset by missile_speed towards missile_angle degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain pathing at missile_point_2 of type Flyability is off) Equal to True
                • Then - Actions
                  • Custom script: call RemoveLocation(udg_missile_point_2)
                  • Set missile_point_2 = missile_point_1
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • missile_hits Greater than 0
                  • missile_distance Greater than 0.00
                • Then - Actions
                  • -------- Different Missiles --------
                  • -------- Shuriken --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of missile) Equal to Shuriken
                    • Then - Actions
                      • Custom script: call DestroyGroup(udg_missile_deflect_group)
                      • Set X = (missile_angle + 90.00)
                      • Set Y = (missile_angle - 90.00)
                      • If (X Greater than or equal to 360.00) then do (Set X = (X - 360.00)) else do (Do nothing)
                      • If (Y Less than or equal to 0.00) then do (Set Y = (Y + 360.00)) else do (Do nothing)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • missile_distance Less than or equal to 1700.00
                          • missile_distance Greater than or equal to 500.00
                          • (Facing of (Picked unit)) Less than or equal to X
                          • (Facing of (Picked unit)) Greater than or equal to Y
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Facing of (Picked unit)) - missile_angle) Greater than or equal to 270.00
                            • Then - Actions
                              • Set missile_angle = (missile_angle - 1.00)
                            • Else - Actions
                              • Set missile_angle = (missile_angle + 1.00)
                        • Else - Actions
                          • Game - Display to (All players) for 0.10 seconds the text: Turn
                      • Hashtable - Save missile_angle as 7 of (Key missile_handle) in missile_hash
                      • Custom script: call DestroyGroup(udg_missile_target_group)
                      • Set missile_target_group = (Units within missile_range of missile_point_2 matching (((Matching unit) Not equal to missile_user) and (((Matching unit) is alive) Equal to True)))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in missile_target_group) Greater than 0
                        • Then - Actions
                          • Set missile_target = (Random unit from missile_target_group)
                          • Unit - Cause Hero[player_number] to damage missile_target, dealing missile_damage damage of attack type Pierce and damage type Normal
                          • Set Temp_Loc_1 = (Position of missile_target)
                          • Unit - Create 1 Dummy for (Player(Player_Number)) at missile_point_1 facing missile_point_2
                          • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                          • Unit - Add Stun (dummy) to (Last created unit)
                          • Unit - Set level of Stun (dummy) for (Last created unit) to 1
                          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt missile_target
                          • Set missile_hits = (missile_hits - 1)
                          • Hashtable - Save missile_hits as 4 of (Key missile_handle) in missile_hash
                        • Else - Actions
                          • Set X = (X of missile_point_2)
                          • Set Y = (Y of missile_point_2)
                          • Set missile_distance = (missile_distance - missile_speed)
                          • Hashtable - Save missile_distance as 6 of (Key missile_handle) in missile_hash
                          • Custom script: call SetUnitX(udg_missile,udg_X)
                          • Custom script: call SetUnitY(udg_missile,udg_Y)
                    • Else - Actions
                  • -------- Grand Fireball --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of missile) Equal to Grand Fireball
                    • Then - Actions
                      • Custom script: call DestroyGroup(udg_missile_target_group)
                      • Set missile_target_group = (Units within missile_range of missile_point_2 matching (((Matching unit) Not equal to missile_user) and (((Matching unit) is alive) Equal to True)))
                      • Set Temp_Loc_1 = (Position of missile)
                      • Special Effect - Create a special effect at Temp_Loc_1 using Objects\Spawnmodels\Other\NeutralBuildingExplosion\NeutralBuildingExplosion.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in missile_target_group) Greater than 0
                        • Then - Actions
                          • Unit Group - Pick every unit in missile_target_group and do (Actions)
                            • Loop - Actions
                              • Set Temp_Loc_2 = (Position of (Picked unit))
                              • Unit - Cause Hero[player_number] to damage (Picked unit), dealing missile_damage damage of attack type Spells and damage type Normal
                              • Unit - Create 1 Dummy for (Player(Player_Number)) at Temp_Loc_1 facing Temp_Loc_2
                              • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                              • Unit - Add Stun (dummy) to (Last created unit)
                              • Unit - Set level of Stun (dummy) for (Last created unit) to 3
                              • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Picked unit)
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • ((Picked unit) is An Ancient) Equal to False
                                • Then - Actions
                                  • Set Temp_Loc_3 = (Temp_Loc_2 offset by 25.00 towards (Angle from Temp_Loc_1 to Temp_Loc_2) degrees)
                                  • Unit - Move (Picked unit) instantly to Temp_Loc_3
                                  • Custom script: call RemoveLocation(udg_Temp_Loc_3)
                                • Else - Actions
                              • Custom script: call RemoveLocation(udg_Temp_Loc_2)
                          • Set missile_hits = (missile_hits - (Number of units in missile_target_group))
                          • Set missile_distance = (missile_distance - missile_speed)
                          • Hashtable - Save missile_distance as 6 of (Key missile_handle) in missile_hash
                          • Hashtable - Save missile_hits as 4 of (Key missile_handle) in missile_hash
                        • Else - Actions
                          • Set X = (X of missile_point_2)
                          • Set Y = (Y of missile_point_2)
                          • Set missile_distance = (missile_distance - missile_speed)
                          • Hashtable - Save missile_distance as 6 of (Key missile_handle) in (Last created hashtable)
                          • Custom script: call SetUnitX(udg_missile,udg_X)
                          • Custom script: call SetUnitY(udg_missile,udg_Y)
                      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
                    • Else - Actions
                  • -------- Phoenix Fire --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of missile) Equal to Fireball
                    • Then - Actions
                      • Custom script: call DestroyGroup(udg_missile_target_group)
                      • Set missile_target_group = (Units within missile_range of missile_point_2 matching (((Matching unit) Not equal to missile_user) and (((Matching unit) is alive) Equal to True)))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in missile_target_group) Greater than 0
                        • Then - Actions
                          • Set missile_target = (Random unit from missile_target_group)
                          • Unit - Cause Hero[player_number] to damage missile_target, dealing missile_damage damage of attack type Pierce and damage type Normal
                          • Set Temp_Loc_1 = (Position of missile_target)
                          • Unit - Create 1 Dummy for (Player(Player_Number)) at missile_point_1 facing missile_point_2
                          • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                          • Unit - Add Stun (dummy) to (Last created unit)
                          • Unit - Set level of Stun (dummy) for (Last created unit) to 4
                          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt missile_target
                          • Set missile_hits = (missile_hits - 1)
                          • Hashtable - Save missile_hits as 4 of (Key missile_handle) in missile_hash
                          • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Other\Doom\DoomDeath.mdl
                          • Special Effect - Destroy (Last created special effect)
                        • Else - Actions
                          • Set X = (X of missile_point_2)
                          • Set Y = (Y of missile_point_2)
                          • Set missile_distance = (missile_distance - missile_speed)
                          • Hashtable - Save missile_distance as 6 of (Key missile_handle) in missile_hash
                          • Custom script: call SetUnitX(udg_missile,udg_X)
                          • Custom script: call SetUnitY(udg_missile,udg_Y)
                    • Else - Actions
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Unit-type of missile) Equal to Fireball
                          • (Unit-type of missile) Equal to Grand Fireball
                          • (Unit-type of missile) Equal to Shuriken
                          • (Unit-type of missile) Equal to Kunai
                    • Then - Actions
                      • Unit Group - Remove missile from missile_group
                      • Unit - Remove missile from the game
                      • Hashtable - Clear all child hashtables of child (Key missile_handle) in missile_hash
                    • Else - Actions
                      • Unit Group - Remove missile from missile_group
              • Custom script: call RemoveLocation(udg_missile_point_1)
              • Custom script: call RemoveLocation(udg_missile_point_2)
        • Else - Actions
          • Trigger - Turn off (This trigger)
 

Slapshot136

Divide et impera
Reaction score
471
I want to adjust the current angle towards the target however I can't seem to get the conditions right. If there is no target then it will continue going straight

how about making your missile face the "Math - angle between points" between your missile and your target (or compare that to your missile's current angle, and adjust it by 1% each iteration)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top