Jump to content

  • Log In with Google      Sign In   
  • Create Account


Stellar RTS planets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Durakken   Members   -  Reputation: 530

Like
3Likes
Like

Posted 28 January 2014 - 09:19 AM

So I want to make a game where you build an galactic empire, sorta like gal civ 2, but more accurate to scale, never ending, and online...

 

Ignoring the problem of online and never ending... I'm having a bit of a problem with "accuracy" 

 

Basically...I want the (accelerated) time and scale to be accurate...

It's impossible to calculate all the positions of all the planets/moons/etc every second (as far as i know) so it seems that I'm at an impasse with what to do as far as the planets (at least not on my PC I can only calc up to around 20,000 orbits at once without noticeable bad slow down)

 

the accelerated time is 1 day = 4 minutes. This also means that if you travel at the speed of light it would take 4 minutes to cross the solar system. Ships have the ability to do more than this and less than this.

 

So the problem is what to do with the planets...

 

I can just have it there sorta as an aesthetic for the player... where when the player goes to the system the planets are displayed to be moving but really aren't which forces all the ships to have an averaged set traveling time.

 

I can also just not have the planets move but that's sorta boring and again, takes away the realistic accuracy because the travel time doesn't change as it would as the planets orbit.

 

i can use some sort combination where if a player isn't watching it uses an averaged time but if the player is watching the system works as it would if i could calculate all the planets for each star.

 

Another solution would be to somehow offset the processing onto other PCs so that when a player logs in they get assigned several stars to calculate and keep track of... but that has all sorts of problems and doesn't solve the problem if not enough players.

 

So any thoughts on this? My current thinking is possibly to just go with the non-moving planets, even though i don't like that solution, it does seem the best.



Sponsor:

#2 Azaral   Members   -  Reputation: 463

Like
4Likes
Like

Posted 28 January 2014 - 11:22 AM

Instead of updating position each tick and storing it you can do something else.

You can create a function that would take the planet and a time variable that is the time passed in the universe since the beginning. It could be of any unit you want, your function would just have to take it into account. Then, whenever you need to deal with the planet's position, you simply calculate it based on the time passed and the properties of the planet (orbit speed, starting location, etc). This way, you avoid having to update any planet's positions and instead just calculate it on the fly when needed. You turn 20,000 updates a tick into one calculation whenever you need it. This would work for any property, orbit position, planet rotation, pretty much anything that is constant with the flow of time, which luckily with space, almost everything is until it get's acted on by something else.

You could use this for any object moving at a constant rate, or for any object you have a constant force on.

As I think, you just need a position function, which is derived from a velocity function, which is derived from an acceleration function, which is derived from a force function.

 

Acceleration = mass / force

 

Position = ( ( acceleration + initial acceleration ) * time ^ 2 ) / 2 + ( velocity + initial velocity ) * time + starting position

 

There are similar functions for a lot of different things, like orbits and what not.

 

You could also have forces chance, but you would have to update your initial acceleration, velocity, and position values.

 

You could also update the variables each time the object's position is calculated to keep it 'current'.
 


Edited by Azaral, 28 January 2014 - 12:06 PM.


#3 Durakken   Members   -  Reputation: 530

Like
2Likes
Like

Posted 28 January 2014 - 02:19 PM

Here's the problem that I'm seeing with that...

 

Hypothetically I can just have a start point, calc the length of the orbit and how many ticks it takes to reach 100% then when load up by a player divide by that...

 

firstly i don't know how to calculate when it would intersect... for example the distance to mars from earth today is different than the distance to mars in a year. Assuming that planet 1 has an orbital radius of 500 and planet 2 has an orbital radius of 499. it could take between 1/1000 of 4 minutes to get there or 4 minutes to get there. Depending on when it intersects. So the only way to figure that out would be to calculate forward changing various angles...wouldn't that just end up being more processing? Especially since it would have to be calculated by all the various ships... though i guess not all at the same time.

 

secondly... i know the origin and destination, so i can predict that, but other planets would then be a problems... that is unless i run the simulation at that point and there again i'd run into the same problem... i think. not sure...

 

 

Also I should point out I think that I'm using C# and unity 3d... if that matters to anyone ^.^ in their thoughts on the subject... and I'm using the function that is built into unity that does the orbit calcs for me since I could find the math to do it myself...



#4 Azaral   Members   -  Reputation: 463

Like
0Likes
Like

Posted 28 January 2014 - 02:55 PM

firstly i don't know how to calculate when it would intersect.

 

secondly... i know the origin and destination, so i can predict that, but other planets would then be a problems... that is unless i run the simulation at that point and there again i'd run into the same problem... i think. not sure...

 

I also do not understand what you mean here, please elaborate.



#5 Durakken   Members   -  Reputation: 530

Like
0Likes
Like

Posted 28 January 2014 - 03:33 PM

The whole problem is that the ship trying to get to the planet. if I don't know where the planet is I can't calculate how to long it takes to get there. Likewise, if I don't know how long to get there i don't know where it is. The planet is moving and because the planet is moving the time it takes to get there changes and because the time it takes to get there changes where the planet is changes which again changes the time it takes to get there.

 

So basically what happens is I have to get the position.vector3 of the planet at the time of departure, get the length which will give me the time to get there. Then jump ahead however many ticks it would take to get there and find where the planet is then which could be any position on a 360 degree orbit...which is likely not the vector3 we originally took. This moving then has to be accounted for somehow, which i don't know how, to get the shortest time possible rather than an get there and then correct for it... with most ships it wouldn't really be an issue, but with some, especially in the early game what would happen is that the ship would continuously chase after the planet and take a really long time to reach it.

 

 

The other problem is a matter of whether or not i calculate the entire solar system and if that is taken into account... which again is another thing i don't quite no how to do as i'd need to detect that i'd run into a planet, plot a course around it, and then recalc to the planet which would then change the time... which means i have to run the calcs for the whole solar system rather than just the planet in question... or i could pretend that prob doesn't exist >.> Not sure if it really even matter considering how big space is...



#6 Azaral   Members   -  Reputation: 463

Like
0Likes
Like

Posted 28 January 2014 - 03:50 PM


The whole problem is that the ship trying to get to the planet. if I don't know where the planet is I can't calculate how to long it takes to get there. Likewise, if I don't know how long to get there i don't know where it is. The planet is moving and because the planet is moving the time it takes to get there changes and because the time it takes to get there changes where the planet is changes which again changes the time it takes to get there.



So basically what happens is I have to get the position.vector3 of the planet at the time of departure, get the length which will give me the time to get there. Then jump ahead however many ticks it would take to get there and find where the planet is then which could be any position on a 360 degree orbit...which is likely not the vector3 we originally took. This moving then has to be accounted for somehow, which i don't know how, to get the shortest time possible rather than an get there and then correct for it... with most ships it wouldn't really be an issue, but with some, especially in the early game what would happen is that the ship would continuously chase after the planet and take a really long time to reach it.

 

Google is your friend. Equations exist for this sort of thing.



#7 TechnoGoth   Crossbones+   -  Reputation: 2682

Like
2Likes
Like

Posted 28 January 2014 - 03:54 PM

Isn't that the only reason to include planetary movement in a game?

The idea is that that depending on the current position of the planets the length of time it takes to travel from earth to mars varies wildly.

 

You would need to an algorithm that determines the point where the ship and mars will intersect and the time to reach that point. To be honest its rather complicated but if you want to take a look at how it calculated you can look at http://www.bogan.ca/orbits/transfer/Earth2Mars.html

 

Unless the game is  going to take place across a small area where travel time is really important then I wouldn't bother doing it.  



#8 Durakken   Members   -  Reputation: 530

Like
0Likes
Like

Posted 28 January 2014 - 04:59 PM

Well see the thing is I just am assuming a relative straight line rather than orbital transfer. 

I was also thinking in terms of everything moving all the time rather than calculating one section at a time to predict out... in which case the ship would just correct itself as it got closer if i set the planet as the target,

 

These ships would be fast enough to at least do that but not fast enough to make it so the planet moving would make no difference.

 

There's no place that really covers what I need. It tells you how NASA does it with our current technology but that's fairly useless if you aren't traveling in a circle or the orbit shape is almost a straight line.



#9 Azaral   Members   -  Reputation: 463

Like
2Likes
Like

Posted 28 January 2014 - 05:03 PM

Well see the thing is I just am assuming a relative straight line rather than orbital transfer. 

I was also thinking in terms of everything moving all the time rather than calculating one section at a time to predict out... in which case the ship would just correct itself as it got closer if i set the planet as the target,

 

These ships would be fast enough to at least do that but not fast enough to make it so the planet moving would make no difference.

 

There's no place that really covers what I need. It tells you how NASA does it with our current technology but that's fairly useless if you aren't traveling in a circle or the orbit shape is almost a straight line.

 

Well, if you want to brute force it this should get you pretty darn close. Figure out how long it will take to get to the destination planet, based on the current desitination and origin. Then figure out how long it would take, and then calculate where the destination will be. Make this your course. Then, after some time, could be a percentage of course traveled, a tick, a certain amount of time, recalculate it. Figure out how long it will take to get to the planet from the current location of ship and planet and figure out where the planet will be at that time and make that the course. It won't be a straight line but it will get to you to your destination.


Edited by Azaral, 28 January 2014 - 05:04 PM.


#10 Durakken   Members   -  Reputation: 530

Like
3Likes
Like

Posted 28 January 2014 - 07:30 PM

Ok I just had a sorta insight but not enough to solve the problem... for me.

 

The ship can travel at 1000 units per 4 minutes

The ship is 456,250 units away from the planet currently (1.25 ly) and at an angle that draws a straight line through the ship, planet and star

ships is 456,750 units from the star

 

let's say the planet is at (0, -500). If you travel straight to this location it should take 1.25 years and the planet should be at (-500, 0).

 

From this there should be some equation that could get to the number, but I'm not that good with math...

The traveling time from the targeted point to the actual point is only 2 minutes, or half a day, and that's not a lot of change. Less than a 1 degree change...  and a ship would know this so they'd target this location... There's just a small bit i'm missing here and it would be solved... but i dunno what it is... something to do with the Pythagorean theorem...

 

edit: Ok if I understand this right...  The number ends up giving me 456.750273673 days vs 456.25 days. or .5 days or .5 * 4 mins with the biggest difference that will be possible... If i understand this right I just have to figure out the distance from the original position of the planet to the position that it would be at the time of arrival at that point, which is essentially the same as going to the first position then the second.

 

Sooo lot easier than i thought it was... assuming the same speed as earth...i just have to figure out how to adjust the values to the right numbers now that i know roughly how to get the right numbers since most planets orbit a lot slower than Earth.


Edited by Durakken, 28 January 2014 - 08:23 PM.


#11 gia   Members   -  Reputation: 139

Like
0Likes
Like

Posted 18 February 2014 - 01:43 AM

well if you arent simulating the entire galaxy rotation and galaxies moving away from each other and stuff, then you could cut corners on more things, because calculating everything sounds like a lot of math.

 

planet 1 is a position X, planet 2 at B now, depending on the situation you would want to WAIT for your launch because another date will provide an EARLIER arrival, for example, if you go all simulator-ish. Also imagine the planets orbits moving them in a way that the sun (or another planet) is on the way, your ship will go through it.

 

I assume you have orbits a a mathematical function?, for in-system travel I'd suggest you calculate the distance to travel at launch, set that as a the travel distance no matter what (even if the planets are accelerating away from each other at the time), and update the travel % each tick if you must (you don't need to know the planets current position for this btw, and no you dont need to update the % every tick either).

 

Then when you need to display the ship on screen, just make a nice spline curve that follows the possible orbit (or counter orbit) between the current position of both planets and set the ship at the correct % of the way, regardless of the actual current distance seen vs traveled, doubt anyone will notice you are off a few light years, or care, even if they do notice. Doing this you could solve the "planet in between" issue by detecting if your ship is inside a planet, and adding an "slingshot" curve around that planet, then draw the ship using it as a slingshot.



#12 suliman   Members   -  Reputation: 554

Like
0Likes
Like

Posted 27 February 2014 - 02:49 PM

Are you sure you need more then 20 000 planets in the game? For what will they all be used?

 

If they are not an important game mechanics (and i dont see how any player can deal with that amount of objects in a meaningful and fun way) you are just wasting resources imho.

 

Are you planning some sort of mega eve online? Might be hard to pull of:)



#13 jefferytitan   Crossbones+   -  Reputation: 2003

Like
0Likes
Like

Posted 27 February 2014 - 04:48 PM

I think I understand your issue. Plotting trajectories including gravity from multiple objects can lead to complex differential equations, especially if you need to skip large amounts of time. Skipping any large chunk of time in physics can lead to different results.

 

My first question is whether you can have fixed planet orbits, rather than calculating them at run-time. If so, then gravity becomes a one-way thing, e.g. planets emit it, ships are acted on by it. That would ease things considerably.

 

I'm not sure about 20,000 planets... yikes! For a much smaller number of planets you could fix the time skipping issue by fudging with precalculated values. e.g. for each pair of planets precalculate some trajectories for various points in the orbits, and use those when the player isn't watching.



#14 Orymus3   Crossbones+   -  Reputation: 7786

Like
0Likes
Like

Posted 03 March 2014 - 09:14 AM


It's impossible to calculate all the positions of all the planets/moons/etc every second (as far as i know) so it seems that I'm at an impasse with what to do as far as the planets (at least not on my PC I can only calc up to around 20,000 orbits at once without noticeable bad slow down)

 

Make objects relative to one another and layer your architecture.

 

What I did was base my map around the position of stars. All planets orbiting a star only have a position that is relative to that star so its easier to update. And all moons have a position that is relative to their parent planet.

 

Makes it much easier, and you can enable/disable updating star children if there is no current visibility (do keep a counter to keep track of time so that when you update everything is in sync).

 

Note: Plotting intercept course for ships might be a bitch when you have to factor movement however. The ETA will not be accurate unless you factor the expected movement of the planet.


Edited by Orymus3, 03 March 2014 - 09:16 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS