• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Help Rotating Spawned Units

Status
Not open for further replies.
Level 2
Joined
Jul 14, 2019
Messages
13
Im looking for help regarding rotating units from one area to an other where they need to keep their position but be able to rotate how they are positioned.
I've looked around on the internet and haven't found a solution and I've also experimented around for a long time now and cant figure it out so if anyone have any tips, suggestions or solutions please help me.

Heres the issue in more detail
Picture: Imgur

So I've managed to keep the positioning when they keep their rotation (From Area 1 to Area 2)
But I need help figuring out how to rotate them and keeping their rotation as shown in the pictures.

So it needs to be able to rotate all the different directions (up, down, left and right)

So when the units will be teleported I will make a variable holding the rotation and the mathematics begind it so it can be used without making a long long trigger.

So if anyone can help me with this it will make my day and make it possible to make my map shine
because right now it gets unfair when your backline fights someones frontline :(

Thanks in advance!
 
Level 41
Joined
Feb 27, 2007
Messages
5,184
Making autochess are you? The solution is very simple, presuming your arena is actually square (not rectangular like your picture).

Find the center point of the arena, then for each unit calculate:
  • Distance from center
  • Angle from center to unit
  • Unit facing
I would save these in set of parallel arrays. Then when you need to spawn the units in an arena, simply add 0, 90, 180, or 270 to both the angles (depending on which way they should face). Spawn units using polar projection from the center of the arena using the original distances but modified angles.
 
Level 2
Joined
Jul 14, 2019
Messages
13
Sadly im not doing autchess, hope there will be some good ones til reforge comes out.
But youre correct they are squares.

Do you think you could do it and show how its done or how its built in the trigger editor?
 
Last edited:
Level 2
Joined
Jul 14, 2019
Messages
13
Making autochess are you? The solution is very simple, presuming your arena is actually square (not rectangular like your picture).

Find the center point of the arena, then for each unit calculate:
  • Distance from center
  • Angle from center to unit
  • Unit facing
I would save these in set of parallel arrays. Then when you need to spawn the units in an arena, simply add 0, 90, 180, or 270 to both the angles (depending on which way they should face). Spawn units using polar projection from the center of the arena using the original distances but modified angles.
I've tried a little bit but im juggling it with my real life studies and more so it haven't worked out yet.
I've managed to keep the positioning and teleport them around and all that but still no clue on the rotation part.
 
Level 41
Joined
Feb 27, 2007
Messages
5,184
  • Set Center = (Center of Region1 <gen>)
  • Set UnitCount = 0
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in Region1 <gen>) and do (Actions)
    • Loop - Actions
      • Set UnitCount = UnitCount + 1
      • Set UnitU[UnitCount] = Picked Unit //or you can store the unit-type if you're recreating them instead of teleporting them
      • Set UnitF[UnitCount] = (Facing of (Picked Unit))
      • Set UnitP = (Position of (Picked Unit))
      • Set UnitD[UnitCount] = (Distance between Center and UnitP)
      • Set UnitA[UnitCount] = (Angle from Center to UnitP)
      • Custom script: call RemoveLocation(udg_UnitP)
  • Set TurnAngle = 180.00 //choose 90 (E) 180 (S) 270 (W) according to which way it should face; I assumed units started facing North
  • For each (Integer A) from 1 to UnitCount do (Actions)
    • Loop - Actions
      • Set UnitP = (Center offset by UnitD[UnitCount] towards (UnitA[UnitCount] + TurnAngle) degrees)
      • Unit - Move UnitU[UnitCount] instantly to UnitP, facing (UnitF[UnitCount] + TurnAngle) degrees
      • Custom script: call RemoveLocation(udg_UnitP)
  • Custom script: call RemoveLocation(udg_Center)
 
Level 2
Joined
Jul 14, 2019
Messages
13
  • Set Center = (Center of Region1 <gen>)
  • Set UnitCount = 0
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in Region1 <gen>) and do (Actions)
    • Loop - Actions
      • Set UnitCount = UnitCount + 1
      • Set UnitU[UnitCount] = Picked Unit //or you can store the unit-type if you're recreating them instead of teleporting them
      • Set UnitF[UnitCount] = (Facing of (Picked Unit))
      • Set UnitP = (Position of (Picked Unit))
      • Set UnitD[UnitCount] = (Distance between Center and UnitP)
      • Set UnitA[UnitCount] = (Angle from Center to UnitP)
      • Custom script: call RemoveLocation(udg_UnitP)
  • Set TurnAngle = 180.00 //choose 90 (E) 180 (S) 270 (W) according to which way it should face; I assumed units started facing North
  • For each (Integer A) from 1 to UnitCount do (Actions)
    • Loop - Actions
      • Set UnitP = (Center offset by UnitD[UnitCount] towards (UnitA[UnitCount] + TurnAngle) degrees)
      • Unit - Move UnitU[UnitCount] instantly to UnitP, facing (UnitF[UnitCount] + TurnAngle) degrees
      • Custom script: call RemoveLocation(udg_UnitP)
  • Custom script: call RemoveLocation(udg_Center)
Thank you, I will give this a try next week!
if it works out I will add you to the credits, thanks so much buddy!
 
Level 2
Joined
Jul 14, 2019
Messages
13
  • Set Center = (Center of Region1 <gen>)
  • Set UnitCount = 0
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in Region1 <gen>) and do (Actions)
    • Loop - Actions
      • Set UnitCount = UnitCount + 1
      • Set UnitU[UnitCount] = Picked Unit //or you can store the unit-type if you're recreating them instead of teleporting them
      • Set UnitF[UnitCount] = (Facing of (Picked Unit))
      • Set UnitP = (Position of (Picked Unit))
      • Set UnitD[UnitCount] = (Distance between Center and UnitP)
      • Set UnitA[UnitCount] = (Angle from Center to UnitP)
      • Custom script: call RemoveLocation(udg_UnitP)
  • Set TurnAngle = 180.00 //choose 90 (E) 180 (S) 270 (W) according to which way it should face; I assumed units started facing North
  • For each (Integer A) from 1 to UnitCount do (Actions)
    • Loop - Actions
      • Set UnitP = (Center offset by UnitD[UnitCount] towards (UnitA[UnitCount] + TurnAngle) degrees)
      • Unit - Move UnitU[UnitCount] instantly to UnitP, facing (UnitF[UnitCount] + TurnAngle) degrees
      • Custom script: call RemoveLocation(udg_UnitP)
  • Custom script: call RemoveLocation(udg_Center)

At the line "Set UnitU[UnitCount] = Picked Unit" How would I be able to set it and store the type for each induvidual unit. So far its working out but then all units that gets "copied" over turns into one type thats set there. Im used to add it all to a Unit group and then spawn them iduvidual from the group. mind sharing how its done with unit-types?
 
Level 2
Joined
Jul 14, 2019
Messages
13
Made an error, should have used Int A in the lower loop.

Set Play = The Player however you get that
...
Set UnitT[UnitCount] = (Unit type of (Picked Unit))
...
Unit - Create 1 UnitT[(Integer A)] for Play at UnitP facing (UnitF[(Integer A)] + TurnAngle) degrees

I tried it and its doing the trick BUT I added a picture explaining the new problem.
 

Attachments

  • a.PNG
    a.PNG
    1.2 MB · Views: 98
Level 2
Joined
Jul 14, 2019
Messages
13
I again made an error and wrote to use UnitP. Obviously you should not do that since it's not an indexed array storing the data. Instead create the unit at CenterPoint offset by UnitD[(Int A)] towards UnitA[(Int A)] degrees.

Hey been some time. I got it figured out and did what you wrote but now the issue is that when they teleport they dont keep their position.
When I change where CenterPoint is they still dont spawn/create at the locaiton I want them to they just endup getting spawned in the same area they are copied from. and when I try it with a different region/variable they dont keep their position.

Do you know what im doing wrong?

P.S Sorry for late reply, been busy with real life stuff.
 
Level 11
Joined
Feb 23, 2009
Messages
577
Howdy Bubo,

Can you link your test map or your trigger? What Pyro suggested is the way to do it, so you probably have an error somewhere, but I can't tell unless I take a look at it ^^...

PS: I've done this exact system for one of my maps where your troops are teleported from your base but retain formation (can even re-angle them while keeping formation - like, everyone face right instead of bot, but keep formation)
 
Level 2
Joined
Jul 14, 2019
Messages
13
Howdy Bubo,

Can you link your test map or your trigger? What Pyro suggested is the way to do it, so you probably have an error somewhere, but I can't tell unless I take a look at it ^^...

PS: I've done this exact system for one of my maps where your troops are teleported from your base but retain formation (can even re-angle them while keeping formation - like, everyone face right instead of bot, but keep formation)

imgur
I cant find anything wrong with it, maybe I've been staring too long for it so it all seems fine.
 
Level 11
Joined
Feb 23, 2009
Messages
577
Use the [ TRIGGER ] (copy triggers as text here) [ /TRIGGER ] block next time ^^

Ok I'm gonna do this a bit differently, it will be faster and simpler I believe, though essentially exactly the same.

PS: I would create new units every time and hide the team while it's "battling" personally, so that you don't need to save any info (just create new units instead of moving them). But that's only if the players keep their units between battles.

PPS: Pyro's way is better (with arrays) only if you NEED to keep those infos, if you don't need to store anything this method is faster and processes faster too.

  • Go
    • Events
      • Player - Player 1 (Red) types a chat message containing a as An exact match
    • Conditions
    • Actions
      • -------- --- --------
      • -------- We are going to calculate all points from the center point --------
      • -------- For both figuring out the initial formation and to place the units --------
      • Set Point_A = (Center of Region 1 <gen>)
      • Set Point_B = (Center of Region 2 <gen>)
      • -------- --- --------
      • Set Group = (Units in Region 1 <gen>)
      • Unit Group - Pick every unit in Group and do (Actions)
        • Loop - Actions
          • Set Point_C = (Position of (Picked unit))
          • Set Point_D = (Point_B offset by (Distance between Point_A and Point_C) towards ((Angle from Point_A to Point_C) - 90.00) degrees)
          • -------- Point_D also contains all the necessary math, like figuring out the angle and distance --------
          • -------- We remove 90 degrees to make a sharp right and rotate the whole formation --------
          • Unit - Move (Picked unit) instantly to Point_D, facing ((Facing of (Picked unit)) - 90.00) degrees
          • -------- --- --------
          • Custom script: call RemoveLocation(udg_Point_C)
          • Custom script: call RemoveLocation(udg_Point_D)
      • Custom script: call DestroyGroup(udg_Group)
      • -------- --- --------
      • Custom script: call RemoveLocation(udg_Point_A)
      • Custom script: call RemoveLocation(udg_Point_B)
 

Attachments

  • Moving Formations.w3x
    18.5 KB · Views: 41
Last edited:
Status
Not open for further replies.
Top