Dev Diary 021: Making Planets Move

Matt Barton's picture

OrbitalOrbitalIt's been awhile since I worked with Unity--been too distracted with Legend of Grimrock. I decided to try to get something done today, breaking apart the project into bite size chunks. I figured I might as well start tackling the heart of the game first, and spent the morning getting a basic system worked out for orbiting the planets around the sun. I'm not quite satisfied with this--for one thing, I can't seem to work out a way to make the planets rotate in sync with their orbit. I'm guessing there's some heavy math involved in something like that, so I might just fudge it. No reason (I can think of) why I can't just pick some textures that won't make much difference how they're angled. In other words, making a ringed planet like Saturn look right would probably drive me nuts, so I might just stick to rocky worlds and gas giants. At any rate, I'm fairly pleased with this part. Now I just need to make some ships that will rotate around their respective planets.

One thing that is already sticking in my craw, though, is screen estate. I think I'm going to have to go above the standard web resolution to make this thing playable. Otherwise, the ships and especially the missiles will just be too small to see. In my estimate, I'm going to need at least twice the present resolution to make it playable. I want the finished version to have at least a half dozen or so orbiting planets, and perhaps some moons thrown in for good measure, to make it really tricky to get the shots right.

Still lots of big hurdles ahead...I'm predicting the hardest part of the gameplay code will be the effects of gravity on the projectiles. Each planet will need to project a gravitational field, so that if a missile gets within range, it'll pull it slightly towards it. And I haven't even started thinking about the multiplayer part yet.

Unity Web Player | WebPlayer

Comments

gilgamesh
Offline
Joined: 03/02/2012
do the math

It's nice to see some progress on this.

What do you mean by "in sync with their orbit"? You want night and day rhythm? The math for rotating the planets is really quite simple. (Just sine and cosine once in the sun's frame of reference and once in the planet's. Elliptic orbits would definitely look cool. )

The force fields could get interesting though. Can't you just tell Unity to attach force fields to the planets?

Matt Barton
Matt Barton's picture
Offline
Joined: 01/16/2006
Math for rotating planets
gilgamesh wrote:

It's nice to see some progress on this.

What do you mean by "in sync with their orbit"? You want night and day rhythm? The math for rotating the planets is really quite simple. (Just sine and cosine once in the sun's frame of reference and once in the planet's. Elliptic orbits would definitely look cool. )

The force fields could get interesting though. Can't you just tell Unity to attach force fields to the planets?

Oh, is that all? I'm clueless! :(

I don't think the rotation of the planets looks quite right. Ideally, they'd just rotate horizontally, but as they're rotated around the sun, their axes are changing. At least, that's what it looks like to me. I might be able to figure out if I keep tweaking it. I don't care at all if it's the same as our own solar system or anything like that; just as long as it looks like what a layperson like me would expect to see.

I haven't looked into how gravity works in Unity yet. I know it's there as part of the physics functions. I just don't know how hard it will be to change from the regular up/down gravity to something like this. I just hope I can adapt whatever is built in to work, because trying to work out formulas on my own will definitely be far above my skill.

Update - I got it. Just a trick of lining the planets up rightly to begin with.

n/a
gilgamesh
Offline
Joined: 03/02/2012
relativity

That is all, but Unity is hiding this inside the function transform.Rotate().

The axes are changing relative to the sun's frame of reference (Space.World if you place the sun into the origin). In the planet's frame of reference (Space.Self) the axes should stay put. And move the camera to get a decent perspective, not the whole scene.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.