• 🏆 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!

Negative angle?

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
From the title itself I'm confused as I didn't think they were even possible (doesn't make sense to me).

Anyway to the point I'm trying to make a spell that makes your hero roll to a target but their rotation is limited so they may miss and turn around etc etc. But I'm checking the facing angle of the caster and the angle between them and their target to check which direction to turn and it's getting the correct facing angle but a negative angle for the angle between points. Which obviously doesn't work as the comparison doesn't work properly and the hero just spins constantly (haven't got to making them move yet)

My trigger is a bit mucked up as I've been trying a number of things to try making it work. Basically, how do I make them turn properly?


EDIT: Still doesn't work but I've undone loads of the trigger so it's postable.

  • Ball Form Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer BallForm_LoopInt) from 1 to BallForm_MaxIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (BallForm_CasterUnit[BallForm_LoopInt] is alive) Equal to True
              • (BallForm_TargetUnit[BallForm_LoopInt] is alive) Equal to True
              • BallForm_Strikes[BallForm_LoopInt] Greater than 0
            • Then - Actions
              • -------- Positions --------
              • Set TempPoint = (Position of BallForm_CasterUnit[BallForm_LoopInt])
              • Set TempReal = (Angle from TempPoint to Spell_TargetPoint)
              • Set Spell_TargetPoint = (Position of BallForm_TargetUnit[BallForm_LoopInt])
              • -------- If facing away slow down --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Facing of BallForm_TargetUnit[BallForm_LoopInt]) Greater than ((Angle from TempPoint to Spell_TargetPoint) + 4.00)
                      • (Facing of BallForm_TargetUnit[BallForm_LoopInt]) Less than ((Angle from TempPoint to Spell_TargetPoint) + 4.00)
                • Then - Actions
                  • Set BallForm_Speed[BallForm_LoopInt] = (BallForm_Speed[BallForm_LoopInt] - ((Default movement speed of BallForm_CasterUnit[BallForm_LoopInt]) x 0.10))
                • Else - Actions
                  • Set BallForm_Speed[BallForm_LoopInt] = (BallForm_Speed[BallForm_LoopInt] + ((Default movement speed of BallForm_CasterUnit[BallForm_LoopInt]) x 0.10))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • BallForm_Speed[BallForm_LoopInt] Greater than ((Default movement speed of BallForm_CasterUnit[BallForm_LoopInt]) x 5.00)
                    • Then - Actions
                      • Set BallForm_Speed[BallForm_LoopInt] = ((Default movement speed of BallForm_CasterUnit[BallForm_LoopInt]) x 5.00)
                    • Else - Actions
              • -------- Rotate --------
              • Unit - Move BallForm_CasterUnit[BallForm_LoopInt] instantly to TempPoint
              • Set TempReal = (Angle from TempPoint to Spell_TargetPoint)
              • Set TempReal = (TempReal + 180.00)
              • Game - Display to (All players) the text: (String(TempReal))
              • Game - Display to (All players) the text: (String((Facing of BallForm_CasterUnit[BallForm_LoopInt])))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Facing of BallForm_TargetUnit[BallForm_LoopInt]) Less than TempReal
                • Then - Actions
                  • Unit - Make BallForm_CasterUnit[BallForm_LoopInt] face ((Facing of BallForm_CasterUnit[BallForm_LoopInt]) - 4.00) over 0.00 seconds
                  • Game - Display to (All players) the text: 1
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Facing of BallForm_TargetUnit[BallForm_LoopInt]) Greater than TempReal
                    • Then - Actions
                      • Unit - Make BallForm_CasterUnit[BallForm_LoopInt] face ((Facing of BallForm_CasterUnit[BallForm_LoopInt]) + 4.00) over 0.00 seconds
                      • Game - Display to (All players) the text: 2
                    • Else - Actions
            • Else - Actions
              • Animation - Remove the alternate animation tag to BallForm_CasterUnit[BallForm_LoopInt]
              • -------- DeIndex --------
              • Set BallForm_CasterUnit[BallForm_LoopInt] = BallForm_CasterUnit[BallForm_MaxIndex]
              • Set BallForm_MaxDamage[BallForm_LoopInt] = BallForm_MaxDamage[BallForm_MaxIndex]
              • Set BallForm_MinDamage[BallForm_LoopInt] = BallForm_MinDamage[BallForm_MaxIndex]
              • Set BallForm_Speed[BallForm_LoopInt] = BallForm_Speed[BallForm_MaxIndex]
              • Set BallForm_Strikes[BallForm_LoopInt] = BallForm_Strikes[BallForm_MaxIndex]
              • Set BallForm_TargetUnit[BallForm_LoopInt] = BallForm_TargetUnit[BallForm_MaxIndex]
              • Set BallForm_MaxIndex = (BallForm_MaxIndex - 1)
              • Set BallForm_LoopInt = (BallForm_LoopInt - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BallForm_MaxIndex Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
I believe your problem comes from here:

Pic2.GIF



The simplest thing you can do is add 360 to all your angles so you will always get positive angles.

Other thing is that you check if teh angle is negative and if it is make it positive number.
 
Level 25
Joined
Sep 26, 2009
Messages
2,387
Facing angle has values from 0 to 360 degrees. Angle between points has values from -180 to +180 degrees, with angle at 0 degrees being same for both.

So a 270 degrees for facing angle is the same as -90 degrees for angle between points (and 225 degrees would be -135 degrees and so on)
 
Level 13
Joined
Oct 16, 2010
Messages
731
I did try times it by -1 when it was negative and I also tried adding 180 to it when it was negative but it still has failed. Part of the issue is that it doesn't realize (for example) that if it is facing 340 and the angle is 10 it is quicker to add rather than subtract, but I also don't know how to fix this either.
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Look at the diagrams above and think how can you turn a negative angle into a positive angle. Neither muliplying by -1 or adding180 will turn it into its 360 deg counterpart.

Facing right is = 0
Up = 90
Down = -90
Left = 180/-180


360angles = 360 + Negative_180_angle

Example:
Negative_180_angle = -50
360angles = 360 + (-50)
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Adding 180? or did you meant 360?

if you have an angle of -90 and add 360, you get 270 which is the same as -90
if you add 180, you end up having 90 which turns only half a circle
multiplying by -1 is interesting but not for this situation.
Because it mirrors the correct one. this could be used for reflection for example
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Convert the angle into its sin/cos for comparison? Due to the cyclic nature of sin/cos and them being defined for any value you will get a comparable quantity no mater the angle you input.

In the case of cos (for straight comparisons) it will be "cos(angle) > X" where X is between 1 and -1 depending on tolerances. with 0 being a tolerance of +/- 90 degrees or pi radians. Inverting it to "cos(angle) < X" allows you to test backwards (opposite direction). Changing to use "sin" instead of "cos" allows you to test relative to the perpendicular. You determine X simply by pushing the appropriate tolerance angle through the appropriate function.

For example if within +/- 5 degrees.
cos(5 degrees) = 0.99619469809174553229501040247389
cos(angle) > 0.99619469809174553229501040247389

This method does not work in reality for very small angle tolerances due do the nature of floating point precision and the functions involved. However for reasonable angles it will work.

This is why it was great to pay attention to mathematics at Highschool.
 
Status
Not open for further replies.
Top