14/02/2020 - My God It's Full Of Stars, And Planets


Before we begin, take a quick look at the gallery because these planets look awesome. The generation for planets might not be perfect at the moment, but it can produce some really interesting results.

Now We're Trucking

So last week I showed off the sprites for the new cargo containers that I intended to use; and this week I actually implemented them. However it isn't perfect. Even after some tweaking, adding more than one trailer to the ship causes some very serious control issues. Momentum is now an issue as I cannot the rotational movement of the containers themselves. So when rotate the ship around, the containers keep going which continues to rotate the ship against my will and I have to make corrections, but then those corrections cause a counter rotation, and it becomes a constant struggle for control.

On the plus side, I made additions to the inventory management script so that it now totals up the complete capacity of all the containers and a complete cargo list. I still need to apply it with the UI I made, but it's a start.

STARS

Finally, I decided to get around to getting random generation of stars and planets.


I'm really happy with how this turned out. Let me talk about the implementation.

So to begin with, I got the idea from this video by OneLoneProgrammer. Although I made some changes to better accommodate what I was doing.

To start off with, I defined the maximum area of the "star system" (or play area if you prefer to be technical), and then broke that down into segments. I currently use a 10 by 10 grid of segments, I find that gives the best results for the sizes I'm currently dealing with.

Within each segment I then spawn a random amount of stars between 1 and a maximum amount I set in the inspector, and then roll a chance for a planet to spawn. Then I just spawn them. And that's it.

It's fairly simple when I put it into those terms, but the amount of code for all that is surprising. Speaking of which, here is the code for it. It's a Pastebin link which some people might not be OK with. Someday I might upload all the scripts to a public repo.

Next week is likely going to be a heavy art week. I'm going to try and get stuff like space stations and other ships drawn. I have a feeling I'm going to have to learn about Unity's sprite tiling the hard way, so I will look into that beforehand.

See you next post.

Get Space Cart

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.