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

Polar Offset

Status
Not open for further replies.
In regular 2D coordinates, a point is defined as some position (x, y) that is x units along the x-axis, and y units along the y-axis. Polar coordinates are slightly different--they are defined by three main things: (1) some origin (2) distance from the origin (3) angle

In math, you'll often just use (0, 0) as the origin. But in Warcraft, we tend to use other things as the origin, e.g. a unit's position.

Now, let's create a scenario--you want to make some unit circle around another unit with a distance of 100 (the radius of the circle is 100). In polar coordinates, this is rather easy--we already have the 'origin' and the 'distance'. We just need to change the angle over time. All you need to do is keep track of an angle and update it periodically.

Open a blank map and try out this code (untested, but it should work):
  • Initialization
    • Events
      • Map Initialization
    • Conditions
    • Actions
      • Set TempLoc = (Center of playable map area)
      • Unit - Create 1 Footman for Player 1 (Red) at TempLoc facing Default building facing degrees
      • Set OriginUnit = (Last created unit)
      • Unit - Create 1 Rifleman for Player 1 (Red) at TempLoc facing Default building facing degrees
      • Set CircleUnit = (Last created unit)
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set CircleAngle = 0.00
  • Circle
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set TempLoc = (Position of (OriginUnit))
      • Set OffsetLoc = (TempLoc offset by 200.00 towards CircleAngle)
      • Unit - Move CircleUnit instantly to OffsetLoc
      • Set CircleAngle = (CircleAngle + 10.00)
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Custom script: call RemoveLocation(udg_OffsetLoc)
All you're doing is you're changing the "CircleAngle" variable. Try it out yourself and see if it makes sense to you. Try changing the radius (200.00) and try changing the angle speed (10.00). See how it affects the path. There are actually pretty cool things you can do with this knowledge--what if you vary the radius? You'll end up with a pretty neat shape. Math is power--the hard part is understanding it. But I find that testing it out with code and fiddling with the variables yourself to be a lot more efficient than reading a wall of text, so give it a go.
 
Status
Not open for further replies.
Top