• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Forcing a unit to face an angle not working

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
I am making a custom movement system for a boat map. I store the player's boat as a unit: u, with custom value 1. I then reference the custom value in other array variables, for example the boat can be ordered to face FlierFacing[1].

The problem is rather simple but as far as I can tell utterly unsolvable! Every .03 seconds, I give the action:

  • Unit - Make u face FlierFacing[tempInteger] over 0.00 seconds
Most of the time it works. You can right-click, a trigger will store that location, compute whether you should turn left or right to reach that point, and then adjusts the FlierFacing variable. The repeat trigger (full trigger below) fires every .03 seconds and the boat slowly turns as FlierFacing[1] is updated slowly.

Sometimes, seemingly at random but consistently (maybe 1 out of 10 times) the boat will jitter back and forth or pause briefly and then suddenly do a dramatic turn. I assumed there was something wrong in my calculation of "FlierFacing" which is the variable that determines where the ship should be facing. So I put the following action in the repeat trigger:

  • Game - Display to (All players) the text: ((flier: + (String(FlierFacing[1]))) + ( facing: + (String((Facing of Fliers[1])))))
This fires every .03 seconds and shows side by side: 1) the direction the ship is being made to face every .03 seconds, and 2) the actual facing of the ship.

What's strange is that they do NOT line up when the boat gets jittery. They can be off by as many as 10 degrees.

In short,

I fire an action that makes unit u face an angle. Unit u, for some reason, does NOT face that angle even though it's being given no other orders, I never use the "face angle" action anywhere else in the map, the action to force the unit to face that direction is given every .03 seconds, and the trigger appears to be programmed correctly because it works 9 times out of 10.

The only thing I can think is that something else in the game mechanics is making the boat turn...like pathing or something, though it seems to happen in the open ocean, I've turned collision off, and I've set the boat's in-game turn rate to 0.

I've put the map in the Pastebin. Just right-click around for a bit (recognize that the current is pulling you east). You should see what I'm talking about and the numbers on the left will not be the same.

http://www.hiveworkshop.com/forums/pastebin_data/mv35eh/_files/river raid.w3x

FULL TRIGGER, it is called by another trigger every .03 seconds
  • Current Move
    • Events
    • Conditions
    • Actions
      • Unit - Make u face FlierFacing[tempInteger] over 0.00 seconds
      • Custom script: set udg_x = GetUnitX(udg_u)
      • Custom script: set udg_y = GetUnitY(udg_u)
      • Set x = (x + ((Cos(CurrentWaterDirection[tempInteger])) x CurrentWaterSpeed[tempInteger]))
      • Set y = (y + ((Sin(CurrentWaterDirection[tempInteger])) x CurrentWaterSpeed[tempInteger]))
      • Set x = (x + ((Cos((Facing of Fliers[tempInteger]))) x FlierSpeed[tempInteger]))
      • Set y = (y + ((Sin((Facing of Fliers[tempInteger]))) x FlierSpeed[tempInteger]))
      • Set tempPoint = (Point(x, y))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Terrain pathing at tempPoint of type Floatability is off) Equal to True
        • Then - Actions
          • -------- *******check point with polar offset, 90 degrees in both directions for pathability******** --------
          • Unit - Set life of u to ((Percentage life of u) - 1.00)%
        • Else - Actions
          • Custom script: call SetUnitX (udg_u, udg_x)
          • Custom script: call SetUnitY (udg_u, udg_y)
      • Custom script: call RemoveLocation (udg_tempPoint)
      • -------- ------- --------
      • -------- turn --------
      • -------- ------- --------
      • Set math_1 = (FlierTurn[tempInteger] - FlierFacing[tempInteger])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • math_1 Less than 0.00
        • Then - Actions
          • Set math_1 = (math_1 + 360.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • math_1 Less than 1.00
              • math_1 Greater than 359.00
        • Then - Actions
          • Set FlierFacing[tempInteger] = FlierTurn[tempInteger]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • math_1 Greater than 180.00
            • Then - Actions
              • Set FlierFacing[tempInteger] = (FlierFacing[tempInteger] - 1.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • FlierFacing[tempInteger] Less than 0.00
                • Then - Actions
                  • Set FlierFacing[tempInteger] = (FlierFacing[tempInteger] + 360.00)
                • Else - Actions
            • Else - Actions
              • Set FlierFacing[tempInteger] = (FlierFacing[tempInteger] + 1.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • FlierFacing[tempInteger] Greater than 360.00
                • Then - Actions
                  • Set FlierFacing[tempInteger] = (FlierFacing[tempInteger] - 360.00)
                • Else - Actions
      • -------- ------- --------
      • -------- adjust water current --------
      • -------- ------- --------
      • Set math_1 = (CurrentWaterDirection[tempInteger] - TargetWaterDirection[tempInteger])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Abs(math_1)) Less than 3.00
              • (Abs(math_1)) Greater than 357.00
        • Then - Actions
          • -------- current water = target --------
          • Set CurrentWaterDirection[tempInteger] = TargetWaterDirection[tempInteger]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • math_1 Less than 0.00
            • Then - Actions
              • Set math_1 = (math_1 + 360.00)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • math_1 Greater than 180.00
            • Then - Actions
              • Set CurrentWaterDirection[tempInteger] = (CurrentWaterDirection[tempInteger] + 2.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CurrentWaterDirection[tempInteger] Less than 0.00
                • Then - Actions
                  • Set CurrentWaterDirection[tempInteger] = (CurrentWaterDirection[tempInteger] + 360.00)
                • Else - Actions
            • Else - Actions
              • Set CurrentWaterDirection[tempInteger] = (CurrentWaterDirection[tempInteger] - 2.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CurrentWaterDirection[tempInteger] Greater than 360.00
                • Then - Actions
                  • Set CurrentWaterDirection[tempInteger] = (CurrentWaterDirection[tempInteger] - 360.00)
                • Else - Actions
      • -------- speed --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaterSpeed[tempInteger] Greater than TargetWaterSpeed[tempInteger]
        • Then - Actions
          • Set CurrentWaterSpeed[tempInteger] = (CurrentWaterSpeed[tempInteger] - 0.05)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CurrentWaterSpeed[tempInteger] Less than TargetWaterSpeed[tempInteger]
            • Then - Actions
              • Set CurrentWaterSpeed[tempInteger] = (CurrentWaterSpeed[tempInteger] + 0.05)
            • Else - Actions
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Why don't you jass it all? It's a lot easier and efficient than doing this with GUI. Where's the "Tempinteger" set?
 
Level 14
Joined
Aug 30, 2004
Messages
909
I'm afraid I don't know anything about JASS. I was given some JASS custom scripts by helpful people here at this website, but that's all I've managed to do with it.

The problem appears to be with the unit's AI...the computer tries to move it to a spot that I right-clicked earlier. I put the unit's turn rate to 0 but that doesn't appear to actually work, as when I disable the trigger and right-click, the unit still turns really slowly.

Anyway, I've been doing a work around by using a dummy unit for the boat and giving move orders to a hidden unit. That way the hidden unit might turn to face the point, but the boat itself received no order and therefore is turned appropriately. It's worked well enough so far.
 
Level 8
Joined
Oct 3, 2008
Messages
367
GUI's unit facey thingy is usually inaccurate by - surprise, surprise - roughly 10 degrees. Can be more or less fixed by replacing your unit facey actiony thingy with a a custom script action containing call SetUnitFacing(udg_u, udg_FlierFacing[udg_TempInteger]). I think.

In the event that it does work, I would like to claim that you can trust me because I'm an azlier.

In the event that it does not work, well, God help you.
 
Level 14
Joined
Aug 30, 2004
Messages
909
GUI's unit facey thingy is usually inaccurate by - surprise, surprise - roughly 10 degrees. Can be more or less fixed by replacing your unit facey actiony thingy with a a custom script action containing call SetUnitFacing(udg_u, udg_FlierFacing[udg_TempInteger]). I think.

In the event that it does work, I would like to claim that you can trust me because I'm an azlier.

In the event that it does not work, well, God help you.

I found the problem; the unit was basically trying to get to the point I told it to move to and it was overriding my custom movement system. I solved the problem by making it a dummy unit and ordering a different unit to move.

Thanks though, and I had a question. Is the JASS SetUnitFacing command more efficient in any way than the GUI command that does the same thing?
 
Status
Not open for further replies.
Top