Elliptical orbits

envenger

Active Member
Reaction score
3
How do i make a unit rotate around another unit in elliptical orbits

with the different values on different side

eg. x on the greater distance and y on smaller distance
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Long Post

An ellipse can be modeled as (x^2/a^2) + (y^2/b^2) = 1, where a and b are the lengths of the horizontal and vertical axes, respectively. That's not overly helpful, but, parametrically, an ellipse can be modeled as:

Code:
X(t) = h + a * cos(t) * cos(w) - b * sin(t) * sin(w)
Y(t) = k + a * cos(t) * sin(w) + b * sin(t) * cos(w)

for 0 <= t <= 2pi
where a and b are the lengths of the horizontal and vertical axes, respectively, 
and w is the angle in radians of rotation from the x-axis
and the point (h, k) is the center of the ellipse.

So, once you determine how long you want your ellipse to be, that will be "a", and tall you want it to be will be "b". Then, you can add random rotation with w (30 degree rotation -> 30/180*pi = .524 radians so w = .524)



Easier to understand:

You are going to be solving for the x and y offsets from the center of your ellipse, using the parameter t. You will simply need to increase t by some constant number every time step, and then resolve your equations using the new t.

JASS:
function ParametricX takes real t, real a, real b, real w returns real
    return a * Cos(t) * Cos(w) - b * Sin(t) * Sin(w)
endfunction

function ParametricY takes real t, real a, real b, real w returns real
    return a * Cos(t) * Sin(w) + b * Sin(t) * Cos(w)
endfunction


So, some looping function:

Trigger:
  • Elliptical Orbit
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Custom script: set udg_T = udg_T + (0.03) * REVOLUTIONS_PER_SECOND * (2*bj_Pi)
      • Custom script: set udg_XOffset = ParametricX(udg_T, WIDTH, HEIGHT, ROTATION * bj_DEGTORAD)
      • Custom script: set udg_YOffset = ParametricY(udg_T, WIDTH, HEIGHT, ROTATION * bj_DEGTORAD)
      • Custom script: call SetUnitX(udg_RotatingUnit, GetUnitX(udg_CenterUnit) + udg_XOffset)
      • Custom script: call SetUnitY(udg_RotatingUnit, GetUnitY(udg_CenterUnit) + udg_YOffset)


Code:
Requiring the following variables:
 - T (real = 0 at init)
 - XOffset (real)
 - YOffset (real)
 - RotatingUnit (unit = your rotating unit)
 - CenterUnit (unit = your center unit)

 - Requiring the JASS script to be pasted into the Custom Script Header.
 - Requiring that you replace the ALL_CAPS_WORDS (except for bj_DEGTORAD)
     with numbers reflecting what you want

(note: a footman in wc3 is 62 'inches' or 'pixels' or 'wtvs' across, so an ellipse that is 10 footmen wide and 5 footmen tall would mean replacing WIDTH with 620 and HEIGHT with 310 -EDIT: actually, I believe that the value is supposed to be half the axis length, so it would be 310 and 155, respectively.)

(note 2: Rotation is in degrees - you can increase that every time step as well for a rotating ellipse effect.)
 

envenger

Active Member
Reaction score
3
Can you plizz make a test map it was very confusing for me
or explain it a bit better for me :p

form

"So, some looping function:" till the end
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top