• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

angle between points

Status
Not open for further replies.
Level 9
Joined
Dec 6, 2007
Messages
233
i'm attempting to create a homing missile using my projectile system. To get the missile to change direction, i'm using the function
  • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
However, the projectile fails to correctly track the target.

Partial trigger for projectile movement:
  • missile launcher shell
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Missile_Shell and do (Actions)
        • Loop - Actions
          • Set Missile_Unit = (Picked unit)
          • Set Missile_Point3 = (Position of Missile_Unit)
          • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Angle from Missile_Point3 to Temp_Unit_Loc) Less than or equal to 30.00
                  • (Angle from Missile_Point3 to Temp_Unit_Loc) Greater than or equal to -30.00
            • Then - Actions
              • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
            • Else - Actions
              • Set Temp_Real = (30.00 x (Sign((Angle from Missile_Point3 to Temp_Unit_Loc))))
          • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards ((Facing of (Picked unit)) + Temp_Real) degrees)
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Unit - Move (Picked unit) instantly to Missile_Point4
The part of that trigger i left out is just for damage calculation and leak killing, i left all the movement stuff in.

I also have another strange problem, that may be linked to the one above. The spawn trigger for the homing missile is this:
  • missile launcher
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Missile Launcher
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Attacking unit)) Equal to Player 1 (Red)
        • Then - Actions
          • Set Shooter_Owner = Player 11 (Dark Green)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Attacking unit)) Equal to Player 2 (Blue)
            • Then - Actions
              • Set Shooter_Owner = Player 12 (Brown)
            • Else - Actions
      • Set Missile_Point1 = (Position of (Attacking unit))
      • Set Missile_Point3 = (Position of (Triggering unit))
      • Set Missile_Point2 = (Missile_Point1 offset by 0.00 towards ((Facing of (Attacking unit)) + 90.00) degrees)
      • Unit - Create 1 Dummy Missile for Shooter_Owner at Missile_Point2 facing Missile_Point3
      • Unit - Add a 5.00 second Generic expiration timer to (Last created unit)
      • Unit Group - Add (Last created unit) to Missile_Shell
      • Hashtable - Save Handle Of(Triggering unit) as Missile_Target of (Key (Last created unit)) in Missile_Target_Hash
      • Custom script: call RemoveLocation(udg_Missile_Point2)
      • Custom script: call RemoveLocation(udg_Missile_Point1)
      • Custom script: call RemoveLocation(udg_Missile_Point3)
      • Trigger - Turn on missile launcher shell <gen>
The projectile does not face the target when it spawns like it should, it's always facing somewhere else. The offset when creating Missile_Point2 is for if i want to change where the missile spawns from on the attacker.
 
Level 13
Joined
Mar 16, 2008
Messages
941
  • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards ((Facing of (Picked unit)) + Temp_Real) degrees)
Why Facing+Temp_Real?
Temp_Real is already the angle from your missle to the target.
For example, when this angle is 180, and the facing at the moment 170, you'd end in the complet entire direction, or?
  • Set Missile_Point2 = (Missile_Point1 offset by 0.00 towards ((Facing of (Attacking unit)) + 90.00) degrees)
Without an offset this does nothing.
 
Level 9
Joined
Dec 6, 2007
Messages
233
If i wanted the missile to go in a straight line, i would do

  • Set Cannon_Point4 = (Cannon_Point3 offset by 100.00 towards (Facing of (Picked unit)) degrees)
(taken from a similar trigger)

But, i want it to change direction, so i add or subtract degrees from it depending on how much it needs to change direction to face the target (i've clamped the max amount of change at 30 degrees).

Without an offset this does nothing.

I know it does nothing without an offset. This trigger is a universal trigger that I use for essentially every projectile from every unit. For some units, the projectile spawns from a different place than the exact middle, hence the offset. When i begin to finalize things for the map i'll take out stuff like that, but while in the development phase i'm leaving it in.

EDIT:mad:gameslayer, that handle is the handle of the missiles target. I'm storing what the missile is trying to kill so i can call it in the movement trigger. Since it's trying to kill the attacked unit, which is the triggering unit, that is not the issue.

EDIT2:Justify, i just figured out what you're trying to say. Ignore first part of above, i'ma test a fix

EDIT3: nope, still doesn't work. New trigger:

  • missile launcher shell
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Missile_Shell and do (Actions)
        • Loop - Actions
          • Set Missile_Unit = (Picked unit)
          • Set Missile_Point3 = (Position of Missile_Unit)
          • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Angle from Missile_Point3 to Temp_Unit_Loc) Less than or equal to 30.00
                  • (Angle from Missile_Point3 to Temp_Unit_Loc) Greater than or equal to -30.00
            • Then - Actions
              • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
            • Else - Actions
              • Set Temp_Real = (30.00 x (Sign((Angle from Missile_Point3 to Temp_Unit_Loc))))
          • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards (Temp_Real - (Facing of (Picked unit))) degrees)
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Unit - Move (Picked unit) instantly to Missile_Point4
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
  • And - All (Conditions) are true
    • (Angle from Missile_Point3 to Temp_Unit_Loc) Less than or equal to 30.00
    • (Angle from Missile_Point3 to Temp_Unit_Loc) Greater than or equal to -30.00
This condition will be true if the target is to the east of missile, which is obviously wrong. You need to include the facing of the unit.
  • Set Temp_real = Modulo( (Angle from Missile_Point3 to Temp_Unit_Loc) - Facing of (Picked unit), 360 )
Then, the condition would be
  • Or - any conditions
    • (Temp_real) less than 30
    • (360 - Temp_real) less than 30
The "angle fix" (=what happens when the target is not in 30 degree cone) should look like this:
  • Set Temp_real = Facing of (Picked unit) - (30 x Sign( Temp_real - 180 ) )
It means that when the difference is less than 180 degrees, it should turn right, when it's bigger than 180, it should turn left. (Note that in this version "Temp_real" is not angle shift, but the angle the missile will face in the end. That way also the second possibility (when the IF-condition is true) will work)

Also, as Justify correctly stated, the final part of the trigger should look like this:
  • Unit - Make (Picked unit) face Temp_real over 0 seconds
  • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards ((Facing of (Picked unit))) degrees)
  • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
  • Unit - Move (Picked unit) instantly to Missile_Point4
  • Custom script: call RemoveLocation(udg_Missile_Point3)
  • Custom script: call RemoveLocation(udg_Missile_Point4)
Also 30 degrees is pretty high number, the missile will be able to make full turn in 0.3 seconds, and needing only 100 units (as in length) for it)

Facing: Can the missiles even turn? If you set movement speed to 0 (which is logical considering it moves by trigger), the game won't display the unit rotation.
 
Level 9
Joined
Dec 6, 2007
Messages
233
mmk, i see what you mean, but where is this "angle fix" to be place in the trigger? Right after the modulo thing?

about turning speed: i thought of that shortly after EDIT2, i will fix that

about facing: i provided a fix for this in another trigger involving changing directions, i was going to include the fix once this worked. Come to think of it now, without the fix, this would never work.

EDIT: The modulo has dividend and divisor, but i see no distinction between the two in your function. Explanation?
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Ok, i'll put it together, i wrote it in a bit chaotic order.
Here it is, ** mark the lines i changed from your previous trigger:
  • missile launcher shell
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Missile_Shell and do (Actions)
        • Loop - Actions
          • Set Missile_Unit = (Picked unit)
          • Set Missile_Point3 = (Position of Missile_Unit)
          • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
          • ** Set Temp_real = Modulo( (Angle from Missile_Point3 to Temp_Unit_Loc) - Facing of (Picked unit), 360 )
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • **Or - any conditions
                • ** (Temp_real) less than 30
                  • **(360 - Temp_real) less than 30
            • Then - Actions
              • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
            • Else - Actions
              • **Set Temp_real = Facing of (Picked unit) - (30 x Sign( Temp_real - 180 ) )
          • **Unit - Make (Picked unit) face Temp_real over 0 seconds
          • **Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards ((Facing of (Picked unit))) degrees)
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Unit - Move (Picked unit) instantly to Missile_Point4
          • **Custom script: call RemoveLocation(udg_Missile_Point3)
          • **Custom script: call RemoveLocation(udg_Missile_Point4)
EDIT: I forgot divisor in the first post (I edited it a while ago, but you propably read it sooner), the divisor is 360 (now fixed in both my posts)
 
Level 9
Joined
Dec 6, 2007
Messages
233
The missiles now circle around endlessly right from where they spawn. New trigger: (i havn't been giving you the whole trigger previously, giving you the whole one now)

  • missile launcher shell
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Missile_Shell and do (Actions)
        • Loop - Actions
          • Set Missile_Unit = (Picked unit)
          • Set Missile_Point3 = (Position of Missile_Unit)
          • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
          • Set Temp_Real = ((Angle from Missile_Point3 to Temp_Unit_Loc) mod 360.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Temp_Real Less than or equal to 30.00
                  • (360.00 - Temp_Real) Less than or equal to 30.00
              • And - All (Conditions) are true
                • Conditions
            • Then - Actions
              • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
            • Else - Actions
              • Set Temp_Real = ((Facing of (Picked unit)) - (30.00 x (Sign((Temp_Real - 180.00)))))
          • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards (Facing of (Picked unit)) degrees)
          • Unit - Make (Picked unit) face Temp_Real over 0.00 seconds
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Unit - Move (Picked unit) instantly to Missile_Point4
          • Set Rocket_Group = (Units within 50.00 of Rocket_Point4 matching (((((Matching unit) is alive) Equal to True) and (((Matching unit) is A sapper) Equal to False)) and (((Owner of (Matching unit)) is an enemy of (Owner of Rocket_Unit)) Equal to True)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Rocket_Group is empty) Equal to False
              • (Rocket_Unit is alive) Equal to True
            • Then - Actions
              • Unit Group - Pick every unit in Rocket_Group and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load (Key armorvalue) of (Key (Picked unit)) from armorhash) Greater than or equal to 50
                    • Then - Actions
                      • Hashtable - Save ((Load (Key armorvalue) of (Key Temp_Unit) from armorhash) - 50) as (Key armorvalue) of (Key Temp_Unit) in armorhash
                    • Else - Actions
                      • Unit - Cause Rocket_Unit to damage (Picked unit), dealing (50.00 - (Real((Load (Key armorvalue) of (Key (Picked unit)) from armorhash)))) damage of attack type Spells and damage type Normal
                      • Hashtable - Save 0 as (Key armorvalue) of (Key (Picked unit)) in armorhash
              • Unit - Kill Rocket_Unit
              • Unit Group - Remove Rocket_Unit from Rocket_Shell
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Rocket_Shell is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
          • Custom script: call DestroyGroup(udg_Missile_Group)
          • Custom script: call RemoveLocation(udg_Missile_Point3)
          • Custom script: call RemoveLocation(udg_Missile_Point4)
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
  • ......
  • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
  • Set Temp_Real = ((Angle from Missile_Point3 to Temp_Unit_Loc) mod 360.00)
  • .....
Again the same mistake as before you don't include facing of the unit.
  • Set Temp_Real = (((Angle from Missile_Point3 to Temp_Unit_Loc) - Facing of (Picked unit)) mod 360.00)
(It was like this in the trigger I posted in previous post, you left it out while copying the trigger).

EDIT: Also, you left an empty "And" block in the IF/THEN/ELSE conditions
 
Level 9
Joined
Dec 6, 2007
Messages
233
oops, your right. But now it's acting stranger. The missile immediately turns when it spawns, then travels straight for a bit, then proceeds to move in a circle until it expires. New Trig:

  • missile launcher shell
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Missile_Shell and do (Actions)
        • Loop - Actions
          • Set Missile_Unit = (Picked unit)
          • Set Missile_Point3 = (Position of Missile_Unit)
          • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
          • Set Temp_Real = (((Angle from Missile_Point3 to Temp_Unit_Loc) - (Facing of (Picked unit))) mod 360.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Temp_Real Less than or equal to 30.00
                  • (360.00 - Temp_Real) Less than or equal to 30.00
            • Then - Actions
              • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
            • Else - Actions
              • Set Temp_Real = ((Facing of (Picked unit)) - (30.00 x (Sign((Temp_Real - 180.00)))))
          • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards (Facing of (Picked unit)) degrees)
          • Unit - Make (Picked unit) face Temp_Real over 0.00 seconds
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Unit - Move (Picked unit) instantly to Missile_Point4
          • Set Rocket_Group = (Units within 50.00 of Rocket_Point4 matching (((((Matching unit) is alive) Equal to True) and (((Matching unit) is A sapper) Equal to False)) and (((Owner of (Matching unit)) is an enemy of (Owner of Rocket_Unit)) Equal to True)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Rocket_Group is empty) Equal to False
              • (Rocket_Unit is alive) Equal to True
            • Then - Actions
              • Unit Group - Pick every unit in Rocket_Group and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load (Key armorvalue) of (Key (Picked unit)) from armorhash) Greater than or equal to 50
                    • Then - Actions
                      • Hashtable - Save ((Load (Key armorvalue) of (Key Temp_Unit) from armorhash) - 50) as (Key armorvalue) of (Key Temp_Unit) in armorhash
                    • Else - Actions
                      • Unit - Cause Rocket_Unit to damage (Picked unit), dealing (50.00 - (Real((Load (Key armorvalue) of (Key (Picked unit)) from armorhash)))) damage of attack type Spells and damage type Normal
                      • Hashtable - Save 0 as (Key armorvalue) of (Key (Picked unit)) in armorhash
              • Unit - Kill Rocket_Unit
              • Unit Group - Remove Rocket_Unit from Rocket_Shell
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Rocket_Shell is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
          • Custom script: call DestroyGroup(udg_Missile_Group)
          • Custom script: call RemoveLocation(udg_Missile_Point3)
          • Custom script: call RemoveLocation(udg_Missile_Point4)
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Well I just tried the trigger, it works, the circling happens when it hits the target. You indeed have a problem in the hit part, units within 50 will, so far I know, return nothnig, because the unit needs to be entirely in the area in order to be selected in this condition. (If it is like 45 units away from the middle, it won't be selected unless its 5 units wide)

EDIT: strange, it worked for me (i let peasant missile hit footman target) and it worked (they both exploded nicely :grin:)

EDIT 2: it is not related to this issue, but you have another mistake here:
  • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards (Facing of (Picked unit)) degrees)
  • Unit - Make (Picked unit) face Temp_Real over 0.00 seconds
It sets the new location BEFORE the new angle, so the missile still moves tovards the old angle. Just reverse the order of these two actions ( or offset towards Temp_real, not towards "facing of unit")

EDIT 3: found MAJOR bug in target detection: you detect units around RocketPoint4, while the missile is at MissilePoint4. Also, you test for enemy of RocketUnit, while the entire trigger works with Missileunit. And lastly, you can't put two "Pick unit group" inside each other.
 
Level 9
Joined
Dec 6, 2007
Messages
233
Very strange indeed. Here is the whole map:

View attachment spacebattletest.w3x

btw, i was testing my large bomb too, and it worked. Watch out for that :D

EDIT: oops, as i said, i use a universal trigger. some things must not have been changed when i transferred over. And i fixed the facing thing, but still no potatoe.
EDIT2: holy crap, i forgot to change the variables on the entire second half of the trigger. New Trigger:

  • missile launcher shell
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Missile_Shell and do (Actions)
        • Loop - Actions
          • Set Missile_Unit = (Picked unit)
          • Set Missile_Point3 = (Position of Missile_Unit)
          • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
          • Set Temp_Real = (((Angle from Missile_Point3 to Temp_Unit_Loc) - (Facing of (Picked unit))) mod 360.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Temp_Real Less than or equal to 30.00
                  • (360.00 - Temp_Real) Less than or equal to 30.00
            • Then - Actions
              • Set Temp_Real = (Angle from Missile_Point3 to Temp_Unit_Loc)
            • Else - Actions
              • Set Temp_Real = ((Facing of (Picked unit)) - (30.00 x (Sign((Temp_Real - 180.00)))))
          • Unit - Make (Picked unit) face Temp_Real over 0.00 seconds
          • Set Missile_Point4 = (Missile_Point3 offset by 50.00 towards (Facing of (Picked unit)) degrees)
          • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
          • Unit - Move (Picked unit) instantly to Missile_Point4
          • Set Missile_Group = (Units within 50.00 of Missile_Point4 matching (((((Matching unit) is alive) Equal to True) and (((Matching unit) is A sapper) Equal to False)) and (((Owner of (Matching unit)) is an enemy of (Owner of Missile_Unit)) Equal to True)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Missile_Group is empty) Equal to False
              • (Missile_Unit is alive) Equal to True
            • Then - Actions
              • Unit Group - Pick every unit in Missile_Group and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load (Key armorvalue) of (Key (Picked unit)) from armorhash) Greater than or equal to 50
                    • Then - Actions
                      • Hashtable - Save ((Load (Key armorvalue) of (Key Temp_Unit) from armorhash) - 50) as (Key armorvalue) of (Key Temp_Unit) in armorhash
                    • Else - Actions
                      • Unit - Cause Missile_Unit to damage (Picked unit), dealing (50.00 - (Real((Load (Key armorvalue) of (Key (Picked unit)) from armorhash)))) damage of attack type Spells and damage type Normal
                      • Hashtable - Save 0 as (Key armorvalue) of (Key (Picked unit)) in armorhash
              • Unit - Kill Missile_Unit
              • Unit Group - Remove Missile_Unit from Missile_Shell
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Missile_Shell is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
          • Custom script: call DestroyGroup(udg_Missile_Group)
          • Custom script: call RemoveLocation(udg_Missile_Point3)
          • Custom script: call RemoveLocation(udg_Missile_Point4)
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Found the bug:
  • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key Missile_Unit) in Missile_Target_Hash))
You used (Key Missile_unit), which seems OK, you actually used "String ID", which is totally wrong. It won't get you anything from the variable, it will just convert the string "Missile_Unit" to some integer value. Use (Key (picked unit)) instead (and use Handle ID)
  • Set Temp_Unit_Loc = (Position of (Load Missile_Target of (Key (Picked unit)) in Missile_Target_Hash))
The entire "hit test" part of the trigger is wrong, you use Rocket_unit everywhere. I fixed it and it works (except for the damage calculation, it causes 0 damage all the time)
 
Level 9
Joined
Dec 6, 2007
Messages
233
lol, noice. Another problem cropped up. It has nothing to do with homing, but i don't feel like spamming the triggers and scripts forum with threads :smile:. I'm designing a system for ship turrets. It basically constantly moves a unit (the turret) to a point with offset from the "ship" (a footman for testing purposes). I have two "turrets" (rifleman), but for some reason, the trigger will only move the first one.

Also, the instant move seems to be stopping him from attacking. Is there a way to allow the rifleman to attack? Triggers:

  • footmen test
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set NonCompound_Group = (Units in (Playable map area) matching (((Matching unit) is in Compound_Group) Equal to False))
      • Unit Group - Pick every unit in NonCompound_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Footman
            • Then - Actions
              • Set Temp_Unit_Loc = (Position of (Picked unit))
              • Unit - Create 1 Rifleman for (Owner of (Picked unit)) at Temp_Unit_Loc facing Default building facing degrees
              • Hashtable - Save Handle Of(Last created unit) as Compound_Footman_Rifle1 of (Key (Picked unit)) in Compound_Hash
              • Unit - Turn collision for (Last created unit) Off
              • Unit - Create 1 Rifleman for (Owner of (Picked unit)) at Temp_Unit_Loc facing Default building facing degrees
              • Hashtable - Save Handle Of(Last created unit) as Compound_Footman_Rifle2 of (Key (Picked unit)) in Compound_Hash
              • Unit - Turn collision for (Last created unit) Off
              • Unit Group - Add (Picked unit) to Compound_Group
            • Else - Actions
      • Custom script: call DestroyGroup(udg_NonCompound_Group)
      • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
  • footmen test function
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Compound_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Footman
            • Then - Actions
              • Set Temp_Unit_Loc = (Position of (Picked unit))
              • Set Temp_Unit_Loc2 = (Temp_Unit_Loc offset by 200.00 towards ((Facing of (Picked unit)) + 270.00) degrees)
              • Unit - Move (Load Compound_Footman_Rifle2 of (Key (Picked unit)) in Compound_Hash) instantly to Temp_Unit_Loc2
              • Set Temp_Unit_Loc3 = (Temp_Unit_Loc offset by 200.00 towards ((Facing of (Picked unit)) + 90.00) degrees)
              • Unit - Move (Load Compound_Footman_Rifle1 of (Key (Picked unit)) in Compound_Hash) instantly to Temp_Unit_Loc3
              • Custom script: call RemoveLocation(udg_Temp_Unit_Loc)
              • Custom script: call RemoveLocation(udg_Temp_Unit_Loc2)
              • Custom script: call RemoveLocation(udg_Temp_Unit_Loc3)
            • Else - Actions
 
Level 9
Joined
Dec 6, 2007
Messages
233
Compound_Footman_Rifle1 and Compound_Footman_Rifle2 are not used anywhere else. The are both integer variables.

EDIT: but what's strange is, if i place the move ...Rifle2 before move ...Rifle1 it move Rifle2, but not Rifle1! otherwise it's vice versa

EDIT2: SetUnitX and SetUnitY are jass, yes? would an example command be
call SetUnitX(unit,X)?
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Well, the exact functions are
JASS:
function SetUnitX(unit u, real x)
function SetUnitY(unit u, real y)
You'll just need to save the unit into some temp variable
  • Set Temp_Unit_Loc3 = (Temp_Unit_Loc offset by 200.00 towards ((Facing of (Picked unit)) + 90.00) degrees)
  • Set Temp_unit = (Load Compound_Footman_Rifle1 of (Key (Picked unit)) in Compound_Hash)
  • Custom script: call SetUnitX( udg_Temp_unit, GetLocationX( udg_Temp_Unit_Loc3 ) )
  • Custom script: call SetUnitY( udg_Temp_unit, GetLocationY( udg_Temp_Unit_Loc3 ) )
then just use the same code for other unit (just change the angle and Compound_Footman_Rifle1 to 2)

Also, as these two don't test for pathing, you can leave out the "Turn collison off" in the init trigger
 
Level 9
Joined
Dec 6, 2007
Messages
233
They can attack now, and they do. But when i stick the footman toe to toe, the rifleman turrets on my footman begin to run away instead of shoot halfway through the fight (well, they try to. It plays the walking animation, but of course they don't go anywhere). Why is this?
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Yeah, thats a problem of the SetUnitX() I forgot about. The units have so called "guard positions", which they tend to return to once they get too far (for example by following enemy unit they auto-acquired to attack).
First thing you can try to get rid of it, is setting the riflemans order to follow the footman. Since the script will always put them close enough to the footman, they should have no desires to move anywhere else. But I am not sure of this.

Second option would be setting guard radius to some huge number like 999999 (that is highest distance thay can move before they start to return - if it is this huge, it will cover entire map)

Last would be using "Move unit" once in a while, so their guard position would be set to their current location, but it would stop their attack at that time.
 
Level 9
Joined
Dec 6, 2007
Messages
233
Found the solution. Oddly enough, you simply have to create a trigger where if your turret attacks something, order it to attack that something. Worked like a charm.

EDIT: scratch that, above doesn't work. I did the guard distance thing, and that seemed to fix it. thanks
 
Last edited:
Status
Not open for further replies.
Top