Stellar RTS planets

Started by
12 comments, last by Orymus3 10 years, 1 month ago

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.

Advertisement

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'.

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...

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.

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...


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.

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.

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 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.

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.

This topic is closed to new replies.

Advertisement