• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Orbiting Planetoids

Status
Not open for further replies.
SOLVED

I'm trying to create a trigger that has a planet orbit a star.

I don't even know where to start.

The math seems simple enough, but I can't figure out how to get a trigger to do it.

There is no function to set a variable to angle between two points, or distance between two points.

Anyone know what to do?

Edit:

  • Planet Rotate
    • Events
      • Timer - Every 0.01 seconds of Game Time
    • Local Variables
    • Conditions
    • Actions
      • Unit Group - Pick each unit in Planets and do (Actions)
        • Actions
          • Unit - Move (Picked unit) instantly to ((Position of (Closest unit to (Position of (Picked unit)) in Stars)) offset by (Distance between (Position of (Closest unit to (Position of (Picked unit)) in Stars)) and (Position of (Picked unit))) towards ((Angle from (Position of (Closest unit to (Position of (Picked unit)) in Stars)) to (Position of (Picked unit))) + 0.1) degrees) (Blend)
      • Unit Group - Pick each unit in Moons and do (Actions)
        • Actions
          • Unit - Move (Picked unit) instantly to ((Position of (Closest unit to (Position of (Picked unit)) in Planets)) offset by 1.5 towards (-1 * Planet Angle) degrees) (Blend)
      • Unit Group - Pick each unit in Structures and do (Actions)
        • Actions
          • Unit - Move (Picked unit) instantly to ((Position of (Closest unit to (Position of (Picked unit)) in Planets)) offset by 1.4 towards (-1 * (Planet Angle + 180)) degrees) (Blend)
 
Last edited:
Glad I could help =p

Unfortunately this way of orbiting is a bit broken.

In theory it's 100% sound, however over time the planets will start to either get closer to the star or farther away, depending on the angle specified.

At 90 degrees (theoretically) they would always be travelling both away and towards the sun equally, however this proves to not be the case in the game.

It's hard to explain what I mean so here's some shitty paint drawings:

IwRNYrf.png


SRIcFfQ.png
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Timer - Every 0.01 seconds of Game Time
This is not possible. The smallest time would be 0.0625 seconds or if you want to represent it in short just put 0. The game works in ticks which at normal speed is 16 ticks per second. The graphics interpolate from these ticks at the display refresh rate (although some people say it caps at 60).

There is no function to set a variable to angle between two points, or distance between two points.
Yes there is...

In theory it's 100% sound, however over time the planets will start to either get closer to the star or farther away, depending on the angle specified.

At 90 degrees (theoretically) they would always be travelling both away and towards the sun equally, however this proves to not be the case in the game.

It's hard to explain what I mean so here's some shitty paint drawings:
If it is anything like your trigger in the first post then it will obviously do strange stuff. I mean you are rounding angles to integers (loss) and picking the closest star each time.

Even if you were not rounding angles to integers you would still have losses due to rounding errors which over time will cause the planet to drift as the errors compound.

The solution (which is what I did for someone else years ago) was to create a orbit mapping which contains state data for the planet on the orbit. This not only is a lot faster since each planet is an element in a list and you already know which star its orbiting but also avoids the errors you are encountering. Instead of moving the planet relative to the planet around the star, you move the planet relative to the star around the star. This means that for each planet orbit star mapping you make you have some dynamic state that represents its current progress on the defined orbit. Since the orbit parameters remain the same (unless you want them to change over time, which could happen from another system or something) the planet will always be at the same place when at the same state of orbit.

Each orbit mapping would define a distance (how far from the sun the planet orbits) and a orbit rate (how many degrees per tick the planet moves). The dynamic state would then be the current angle the planet is on its orbit which is incremented by the degrees per tick every tick (1/16 of a second). From this, finding the next position for the planet is as simple as a polar offset originating at the sun. You will need some logic to handle angle overflow since the overflow of reals from positive to negative may cause the planet to rapidly shift orbit state.

You might also be thinking that this clearly is not how orbits work in real life, which is correct but neither is your implementation. Since time is continuous in real life the actual results would have several integral terms to compensate for the tick based sampling done. Also there is seldom something such as a perfect orbit, with many bodies such as planets and moons drifting to or away from each other over time. Eventually Earth may lose its moon, as an example, but before the sun dies is another question.
 
This is not possible. The smallest time would be 0.0625 seconds or if you want to represent [...]

I've been working on this for hours but everything I try fails.

If I correctly understand what you're saying then..

  • Planet Rotate
    • Events
      • Timer - Every 0.01 seconds of Game Time
    • Local Variables
    • Conditions
    • Actions
      • Unit Group - Pick each unit in Planets and do (Actions)
        • Actions
          • Unit - Move (Picked unit) instantly to ((Position of (Closest unit to (Position of (Picked unit)) in Stars)) offset by (Distance between (Position of (Picked unit)) and (Position of (Closest unit to (Position of (Picked unit)) in Stars))) towards (Abs((Angle from (Position of (Picked unit)) to (Position of (Closest unit to (Position of (Picked unit)) in Stars))))) degrees) (Blend)
Causes massive errors.

I tried calculating the distance between the planet and sun, then setting the planet to move to the sun, offset by that distance, by its current angle to the sun +1 but the solutions cause massive errors and the planets fly all over the place.

The only thing I havn't tried yet that I don't want to resort to is locking the angle to the planet's facing angle + the current angle between the star and planet. This would look cheap, as the planets would move along exactly with the star.

Keep in mind I switched to using reals awhile ago, instead of integers.

I even tried setting the angle it moves at to a static number that increase gradually (global variable, with a separate trigger increasing it), and that seems to work best so far, however; 1) there are many planets per solar system which are randomly generated at the start of the map, and they all have separate angles. Even with the equation (current angle + static angle) or (current angle - static angle) it glitches, 2) when the planet follows a static orbit, every 90 degrees it shifts away from the sun for some unknown reason.

I'll create a quick map and upload it here. Hopefully you can show me what you mean.

Edit:

My good fucking god. The problem was in my trigger.

Init Orbit
Events
Timer - Every 0.0 seconds of Game Time
Local Variables
Conditions
Actions
Unit Group - Pick each unit in Planets and do (Actions)
Actions
Unit - Move (Picked unit) instantly to ((Position of (Closest unit to (Position of (Picked unit)) in Stars)) offset by (Distance between (Position of (Picked unit)) and (Position of (Closest unit to (Position of (Picked unit)) in Stars))) towards ((Angle from (Position of (Picked unit)) to (Position of Siege Tank (Siege Mode) [46.66, 52.11])) + 1.0) degrees) (No Blend)
Init Orbit
Events
Timer - Every 0.0 seconds of Game Time
Local Variables
Conditions
Actions
Unit Group - Pick each unit in Planets and do (Actions)
Actions
Unit - Move (Picked unit) instantly to ((Position of (Closest unit to (Position of (Picked unit)) in Stars)) offset by (Distance between (Position of (Picked unit)) and (Position of (Closest unit to (Position of (Picked unit)) in Stars))) towards ((Angle from (Position of Siege Tank (Siege Mode) [46.66, 52.11]) to (Position of (Picked unit))) + 1.0) degrees) (No Blend)


All I did was switch the reference point to the angle from the picked unit to the star...

Edit2: Nevermind. The planets are still colliding with each other and stars.
 
Last edited:
Status
Not open for further replies.
Top