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

Rotating Buildings

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Edit: This is how you can rotate the facing angle of a building:
  • Rotate
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Set variables --------
      • Set Building = Farm 0006 <gen>
      • Set Point = (Position of Building)
      • Set Angle = ((Facing of Building) + 90.00)
      • -------- - --------
      • -------- Adjust the angle. Note that "Make Unit face Angle" doesn't work otherwise I'd use it here. --------
      • Unit - Move Building instantly to Point, facing Angle degrees
      • -------- - --------
      • -------- Clean up leaks --------
      • Custom script: call RemoveLocation(udg_Point)
Note that if you Rotate it multiple times in a small time frame the angle will fall off and you'll end up with angles like 246.423 degrees instead of 90, 180, 270, 360. Also, for whatever reason, this trigger doesn't work the first time you do it.

I attached a map with an example of how you can do this with an ability. From testing it appears as though 0.50 seconds is about as low of a cooldown you can have for the ability before running into the precision problems that I mentioned before. To fix this, I stored the degrees 1.00 to 360.00 in a Variable called Angles and reference this instead of doing Arithmetic like "Facing of building + 90.00". There's probably a better way of doing this but it works.
 

Attachments

  • Rotate Buildings 1.w3x
    23.4 KB · Views: 52
Last edited:
Level 13
Joined
Jul 2, 2015
Messages
872
Edit: This is how you can rotate the facing angle of a building:
  • Rotate
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Set variables --------
      • Set Building = Farm 0006 <gen>
      • Set Point = (Position of Building)
      • Set Angle = ((Facing of Building) + 90.00)
      • -------- - --------
      • -------- Adjust the angle. Note that "Make Unit face Angle" doesn't work otherwise I'd use it here. --------
      • Unit - Move Building instantly to Point, facing Angle degrees
      • -------- - --------
      • -------- Clean up leaks --------
      • Custom script: call RemoveLocation(udg_Point)
Note that if you Rotate it multiple times in a small time frame the angle will fall off and you'll end up with angles like 246.423 degrees instead of 90, 180, 270, 360. Also, for whatever reason, this trigger doesn't work the first time you do it.

I attached a map with an example of how you can do this with an ability. From testing it appears as though 0.50 seconds is about as low of a cooldown you can have for the ability before running into the precision problems that I mentioned before. To fix this, I stored the degrees 1.00 to 360.00 in a Variable called Angles and reference this instead of doing Arithmetic like "Facing of building + 90.00". There's probably a better way of doing this but it works.
It works fantastically! The only thing that annoys me a tad bit is that if I use 45 degrees, its off by a bit. Like 360 is supposed to be facing (Downward if from top down view) but its slightly off by a few degrees right. How'd I fix this?

(Currently attempting fixing a compiling Error from the Unit Indexer)
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
I'm still a bit confused as to what's going on myself. I have no idea why it doesn't Rotate the first time.

And keep in mind, if you use the system in the attached map then you will have to adjust the If Else Statement in the Rotate trigger to this:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • AngleIndex[CV] Not equal to 360
    • Then - Actions
      • Set AngleIndex[CV] = (AngleIndex[CV] + 45)
    • Else - Actions
      • Set AngleIndex[CV] = 45
By default your buildings AngleIndex[CV] will be equal to 270 (It's default angle). So when you cast the Rotate ability, I increase the AngleIndex[CV] by 45 (or however much you want to rotate). However, if you're already facing 360 degrees aka AngleIndex[CV] = 360 then we need to reset the angle to 45. If we don't reset it, then it would add 360 + 45 giving us an angle of 405.

Long story short: Integers don't lose precision when using Arithmetic like X + X but Reals do. So this little setup I made just avoids using Arithmetic with Reals and does it with Integers instead.
 
Last edited:
Level 13
Joined
Jul 2, 2015
Messages
872
I'm still a bit confused as to what's going on myself. I have no idea why it doesn't Rotate the first time.

And keep in mind, if you use the system in the attached map then you will have to adjust the If Else Statement in the Rotate trigger to this:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • AngleIndex[CV] Not equal to 360
    • Then - Actions
      • Set AngleIndex[CV] = (AngleIndex[CV] + 45)
    • Else - Actions
      • Set AngleIndex[CV] = 45
By default your buildings AngleIndex[CV] will be equal to 270 (It's default angle). So when you cast the Rotate ability, I increase the AngleIndex[CV] by 45 (or however much you want to rotate). However, if you're already facing 360 degrees aka AngleIndex[CV] = 360 then we need to reset the angle to 45. If we don't reset it, then it would add 360 + 45 giving us an angle of 405.
Yeah that's exactly what I did, I mean, I guess Oh well? My main concern rn is that fact that the Unit Indexer breaks the map with its 'compiling errors'. If I disable it map works fine, if I enable it, it doesn't.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Yeah, then you're definitely on Jass. Older maps seem to have weird problems even if you're up to date. What does the error say?

Also, it just dawned on me. The problem with the angles is because Building's default facing angle is 270 degrees, but the actual model of the Building is facing an angle unique to the model. So when a Farm is facing 270 degrees, it's model is actually facing what looks like 225 degrees. This differs depending on the model of the building.
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
The problem is that you have 2 of the same unit indexer trigger, so it's trying to redeclare a function that already exists. One under Requirements > Unit Indexer and one under Buildings/Units > Rotate Building > Unit Indexer (Bribe) > Unit Indexer Copy. Delete one of them.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Here's another version of the map. Still buggy and not working the way I want but with some slight improvements. For some reason the Building's ignore the first rotation... No clue why.

Also, the Unit Indexer you were using in the folder "Requirements" is outdated so I recommend using the one from my map.
 

Attachments

  • Rotate Buildings 2.w3x
    23.3 KB · Views: 41
Last edited:
Level 13
Joined
Jul 2, 2015
Messages
872
The problem is that you have 2 of the same unit indexer trigger, so it's trying to redeclare a function that already exists. One under Requirements > Unit Indexer and one under Buildings/Units > Rotate Building > Unit Indexer (Bribe) > Unit Indexer Copy. Delete one of them.
Here's another version of the map. Still buggy and not working the way I want but with some slight improvements. For some reason the Building's ignore the first rotation... No clue why.

Also, the Unit Indexer you were using in the folder "Requirements" is outdated so I recommend using the one from my map.
Thanks! Removed the old Indexer.

The new version functions alot better, but for some reason it gives "Repair" to all of my buildings??
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Oh, it adds the "Rotate" ability to all of your buildings. But that ability has a different id in your map so you end up getting Repair instead. You have to change it/delete it from the "Initial Values" trigger.

It's really up to you in how you want to actually do the Rotation. You can easily edit the Rotate trigger to suit your needs. For example, if you don't want all of your buildings to have the Rotate ability then you could use a chat message like -rotate90 or maybe give some Commander unit the ability to Rotate a targeted building.
 
Last edited:
Level 13
Joined
Jul 2, 2015
Messages
872
Oh, it adds the "Rotate" ability to all of your buildings. But that ability has a different id in your map so you end up getting Repair in this case. You have to change it/delete it from the "Initial Values" trigger.

It's really up to you in how you want to actually do the Rotation. You can easily edit the Rotate trigger to suit your needs. For example, if you don't want all of your buildings to have the Rotate ability then you could use a chat message like -rotate90 or maybe give some Commander unit the ability to Rotate a targeted building.
Works fantastically! Many thanks sir!
 
Status
Not open for further replies.
Top