Rockets

Status
Not open for further replies.
Level 5
Joined
Feb 21, 2009
Messages
136
Okay so I made this Missile Rocket system.. and I want it so that the rocket cannot make short angles.. like that if the target is behind the rocket it will turn around within milliseconds.. Negative angles probably don't even exist, I'm just very confused.. How can I fix this?
  • Rocket
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in Temp_Force and do (Actions)
        • Loop - Actions
          • Set Temp_Point = (Position of Rocket[(Player number of (Picked player))])
          • Set Temp_Point2 = (Position of RocketTraget[(Player number of (Picked player))])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Point and Temp_Point2) Less than or equal to 90.00
              • (Rocket[(Player number of (Picked player))] is alive) Equal to True
            • Then - Actions
              • Custom script: call RemoveLocation (udg_Temp_Point)
              • Custom script: call RemoveLocation (udg_Temp_Point2)
              • Unit - Cause Rocket[(Player number of (Picked player))] to damage RocketTraget[(Player number of (Picked player))], dealing 5000.00 damage of attack type Spells and damage type Normal
              • Unit - Kill Rocket[(Player number of (Picked player))]
            • Else - Actions
              • Custom script: call RemoveLocation (udg_Temp_Point)
              • Custom script: call RemoveLocation (udg_Temp_Point2)
              • Set Temp_Point2 = (Position of Rocket[(Player number of (Picked player))])
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of RocketTraget[(Player number of (Picked player))]) Equal to Transport Helicopter
                • Then - Actions
                  • Set Temp_Point = (Position of RocketTraget[(Player number of (Picked player))])
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Angle from Temp_Point2 to Temp_Point) Less than or equal to 5.00
                      • (Angle from Temp_Point2 to Temp_Point) Greater than or equal to -5.00
                    • Then - Actions
                      • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point2, facing (Angle from Temp_Point2 to Temp_Point) degrees
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Angle from Temp_Point2 to Temp_Point) Less than 5.00
                        • Then - Actions
                          • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point2, facing ((Facing of Rocket[(Player number of (Picked player))]) + 5.00) degrees
                        • Else - Actions
                          • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point2, facing ((Facing of Rocket[(Player number of (Picked player))]) - 5.00) degrees
                  • Custom script: call RemoveLocation (udg_Temp_Point)
                • Else - Actions
              • Set Temp_Point = (Temp_Point2 offset by 55.00 towards (Facing of Rocket[(Player number of (Picked player))]) degrees)
              • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point
              • Custom script: call RemoveLocation (udg_Temp_Point)
              • Custom script: call RemoveLocation (udg_Temp_Point2)
  • Then - Actions
    • Set Temp_Point = (Position of RocketTraget[(Player number of (Picked player))])
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Angle from Temp_Point2 to Temp_Point) Less than or equal to 5.00
        • (Angle from Temp_Point2 to Temp_Point) Greater than or equal to -5.00
      • Then - Actions
        • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point2, facing (Angle from Temp_Point2 to Temp_Point) degrees
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Angle from Temp_Point2 to Temp_Point) Less than 5.00
          • Then - Actions
            • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point2, facing ((Facing of Rocket[(Player number of (Picked player))]) + 5.00) degrees
          • Else - Actions
            • Unit - Move Rocket[(Player number of (Picked player))] instantly to Temp_Point2, facing ((Facing of Rocket[(Player number of (Picked player))]) - 5.00) degrees
    • Custom script: call RemoveLocation (udg_Temp_Point)
 
Negative angles do exist. I think angles in wc3 go from -360 to (insert huge number here). But it's best to contain the angle within the range of 0 to 360. So you should have an if statement that does "if angle less than 0 then set angle to angle + 360", and "if angle greater than 360 then set angle to angle - 360". I think then it would be easier to contain your angle within certain degrees.
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Element of Water: you can do that even simplier, without ifs:
  • Set Angle = (Angle +360) mod 360
The part two is
  • If colission ......
    • ELSE
      • Set Temp_Point = (Position of RocketTraget[(Player number of (Picked player))])
      • Set Angle = ( (Angle from Temp_Point2 to Temp_Point) +360 ) mod 360
      • Set Facing = ( (Facing of Rocket[(Player number of (Picked player))]) +360) mod 360
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Abs ( Angle ) Less than or equal to 5.00
        • Then - Actions
          • Unit - Make Rocket[(Player number of (Picked player))] face (Angle) over 0
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • Conditions
              • (Angle) < (Facing)
            • Then - Actions
              • Unit - Make Rocket[(Player number of (Picked player))] face (Facing - 5.00) over 0
            • Else - Actions
              • Unit - Make Rocket[(Player number of (Picked player))] face (Facing + 5.00) over 0
    • Custom script: call RemoveLocation (udg_Temp_Point)
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Meh the modulo function (the Jass code for it) uses ifs anyway...
I though something like this would be native, but your right!:grin:

I noticed another thing in definition of modulo: you don't have to add +360 to the value, modulo function automatically shifts the value to the 0..359 range. Correction of my codes above:
  • Set Angle = Angle mod 360
 
Status
Not open for further replies.
Top