• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Turning problems

Status
Not open for further replies.
Level 7
Joined
Apr 1, 2010
Messages
289
Math problem

  • Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MSGroup and do (Actions)
        • Loop - Actions
          • Set MSUnit = (Picked unit)
          • Custom script: set udg_Handle = GetHandleIdBJ(udg_MSUnit)
          • -------- here is wher all Hastable Values are Loaded. --------
          • -------- This Involves Speed --------
          • Set MSSpeed = (Load 0 of Handle from MS)
          • Set MSGSpeed = (Load 1 of Handle from MS)
          • Set MSAccel = (Load 2 of Handle from MS)
          • -------- This involves Facing --------
          • Set MSAngle = (Load 3 of Handle from MS)
          • Set MSGAngle = (Load 4 of Handle from MS)
          • Set MSTurn = (Load 5 of Handle from MS)
          • -------- The Location is loaded from Hastables. --------
          • Set TempPoint1 = (Load 6 of Handle in MS)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MSSpeed Not equal to MSGSpeed
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Abs((MSGSpeed - MSSpeed))) Less than or equal to MSAccel
                • Then - Actions
                  • Set MSSpeed = MSGSpeed
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • MSGSpeed Less than MSSpeed
                    • Then - Actions
                      • Game - Display to (All players) the text: Increasing Speed
                      • Set MSSpeed = (MSSpeed - MSAccel)
                    • Else - Actions
              • Set MSSpeed = (MSSpeed + MSAccel)
              • Hashtable - Save MSSpeed as 0 of Handle in MS
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MSAngle Not equal to MSGAngle
            • Then - Actions
              • Set Real1 = (Acos((Cos((MSGAngle - MSAngle)))))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Real1 Less than or equal to MSAccel
                • Then - Actions
                  • Set MSAngle = MSGAngle
                • Else - Actions
                  • Set Real1 = (Acos((Cos((MSAngle - MSGAngle)))))
                  • Set Real2 = (Asin((Cos((MSAngle + MSGAngle)))))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Real1 Less than Real2
                    • Then - Actions
                      • Set MSAngle = (MSAngle - MSTurn)
                    • Else - Actions
                      • Set MSAngle = (MSAngle + MSTurn)
              • Hashtable - Save MSAngle as 3 of Handle in MS
            • Else - Actions
          • Set TempPoint2 = (TempPoint1 offset by MSSpeed towards MSAngle degrees)
          • Hashtable - Save Handle OfTempPoint2 as 6 of Handle in MS
          • Custom script: call SetUnitFacing(udg_MSUnit, udg_MSAngle)
          • Custom script: call SetUnitX(udg_MSUnit, GetLocationX(udg_TempPoint2))
          • Custom script: call SetUnitY(udg_MSUnit, GetLocationY(udg_TempPoint2))
          • Custom script: call RemoveLocation(udg_TempPoint1)
the problem is with the turning. i tried to make take the shortest direction but it isn't working.
Another question is there a way to force a unit to face a direction. without using the gui move instantly?

edit: solved thanks to Mage goo
[hidden = "Solution"]
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • MSAngle Not equal to MSGAngle
    • Then - Actions
      • Set Real1 = (Acos((Cos((MSGAngle - MSAngle)))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Real1 Less than or equal to MSAccel
        • Then - Actions
          • Set MSAngle = MSGAngle
        • Else - Actions
          • Set Real1 = (MSGAngle - MSAngle)
          • Set Real1 = (Acos((Cos(Real1))))
          • Set Real2 = (MSAngle - MSGAngle)
          • Set Real2 = (Acos((Cos(Real2))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Real1 Less than Real2
            • Then - Actions
              • Set MSAngle = (MSAngle - MSTurn)
            • Else - Actions
              • Set MSAngle = (MSAngle + MSTurn)
      • Hashtable - Save MSAngle as 3 of Handle in MS
    • Else - Actions
what this does is find the shortest direction for an angle change., Clockwise or Counter-Clockwise[/hidden]
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
What is it that you're trying to do? Explain the system.

Get rid of
  • Custom script: set udg_Handle = GetHandleIdBJ(udg_MSUnit)
it does the same as
  • Set Handle = (Key (Picked unit))
There's no way to instantly force a unit's facing, the turn rate is limited in speed.
 
Level 7
Joined
Apr 1, 2010
Messages
289
What is it that you're trying to do? Explain the system.

Get rid of
  • Custom script: set udg_Handle = GetHandleIdBJ(udg_MSUnit)
it does the same as
  • Set Handle = (Key (Picked unit))
There's no way to instantly force a unit's facing, the turn rate is limited in speed.

  • Set Handle = (Key (Picked unit))
thought i got rid of that,
what i want it to do is cause the unit to turn and move

what about the GUI one?
  • Unit - Move (Triggering unit) instantly to (Center of (Playable map area)), facing Default building facing degrees
i would use this one but SetUnitX/Y is a lot more efficient.

what i am trying to do is say the units current facing = 90 and the facing i want it too have is 269 i won't it two slowly turn to that angle taking the shortest amount of time(the smallest angular direction whether it be clock or counter)
This is where my trigger has bugs
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • MSAngle Not equal to MSGAngle
    • Then - Actions
      • Set Real1 = (Acos((Cos((MSGAngle - MSAngle)))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Real1 Less than or equal to MSAccel
        • Then - Actions
          • Set MSAngle = MSGAngle
        • Else - Actions
          • Set Real1 = (Acos((Cos((MSAngle - MSGAngle)))))
          • Set Real2 = (Asin((Cos((MSAngle + MSGAngle)))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Real1 Less than Real2
            • Then - Actions
              • Set MSAngle = (MSAngle - MSTurn)
            • Else - Actions
              • Set MSAngle = (MSAngle + MSTurn)
      • Hashtable - Save MSAngle as 3 of Handle in MS
    • Else - Actions
here is an example map View attachment Narogogs MoveSys.w3x
 
Level 10
Joined
Jun 1, 2008
Messages
485
urm.. I think u can use this to change unit facing
  • Unit - Make <Unit> face <Angle in real> over 0.00 seconds
and... for your question to check whether it's shorter to turn clockwise or counter clockwise...
  • Set Unit_Facing_Angle = (Facing of <Unit>)
  • Set Target_Angle = <Facing u want to have>
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Target_Angle - Unit_Facing_Angle) Greater than or equal to (Unit_Facing_Angle - Target_Angle)
    • Then - Actions
      • <Turn Clockwise>
    • Else - Actions
      • <Turn Counter-Clockwise>
 
Level 10
Joined
Jun 1, 2008
Messages
485
Mage_Goo, you sure that works for negative angles?
I believe so. But in his case, I don't think that the angle will ever be negative. But maybe it's better to mod it by 360 in case it's negative

no that won't work, it only functions if the unit is doing nothing.
It's not the same thing with SetUnitFacing in JASS? I always thought they are the same.
your other suggestion mostly worked i just added a acos(cos()) to each of it thanks: )
what's the point of add acos(cos())? to convert the negative angle to positive counterpart?(-90 to 270). isn't it better to use mod 360 in that case? isn't the acos(cos()) function would have many decimal and make it less accurate? well, only for a really little inaccurate though.
 
Level 7
Joined
Apr 1, 2010
Messages
289
what it does is make the angle positive, with your one occasionally it would take the longest path. but if you acos(cos()) it, it converts it to a positive number that gives the positve angle offset.
anyway thanks for helping me solve this problem.
 
Level 10
Joined
Jun 1, 2008
Messages
485
oops.
Just realized that I was switched in turn clockwise and counter clockwise part.
with your one occasionally it would take the longest path.
I've tried it with some angle. It works if both unit facing angle and target angle are positive angle or both are negative angle, but won't work if it's different type (positive with negative). you're right 'bout this one.
but if you acos(cos()) it, it converts it to a positive number that gives the positve angle offset.
wait... cos(0 to 90) is the same as cos(0 to 270) (cos(45) = cos(315)). so... acos(cos(315)) = 45? if u use it, sometimes it will get wrong...
 
Level 7
Joined
Apr 1, 2010
Messages
289
wait... cos(0 to 90) is the same as cos(0 to 270) (cos(45) = cos(315)). so... acos(cos(315)) = 45? if u use it, sometimes it will get wrong... not quite the graph of Cosine is symmetrical about the X axis and cos(45) is not = Cos(315) you are thinking of Sine because Sin(45)=sin(315) any way, i fixed the problem.(see my first post)
 
Last edited:
Level 10
Joined
Jun 1, 2008
Messages
485
not quite the graph of Cosine is symmetrical about the and cos(45) is not = Cos(315) you are thinking of Sine because Sin(45)=sin(315)
well, if u look at the graph:
sinxbasic.gif

cos-graph.jpg

u can see that both have different-angle-but-same-value there. if u use only one of it, it will sometimes make mistake.
like, if the angle is -45, which is normally 315, if u use acos(cos(-45)), it will become 45, not 315.
if u use asin(sin(-45)), it will become 315 though, but the asin(sin()) will wrong if the angle is like...-181. asin(sin(-181)) will return 1, while it's right positive angle is 179.
well, but seeing that it's work, u can always ignore this.
 
Status
Not open for further replies.
Top