4X Space Game Tidy Up 1 (between parts 5 and 6)

Hi guys, this post isn’t a tutorial. As promised in Part 5 I have tidied things up a bit in the code.

Scripts Before Part 6 (Paste Bin – P006_PositionMath, P006_SpaceObjects, Galaxy_BeforePart6 and SolarSystem_BeforePart6)

scripts_before_part_6 (zip file)


  • I have added two new scripts called SpaceObjects and PositionMath. To add them to the project download them and add them to the assets\scripts folder (be sure to rename them to get rid of the “_BeginningOfPart6” part of the name otherwise they will not work).
  • PositionMath contains several methods used to calculate the position of our objects. The RandomPosition method in the Galaxy script has been moved here. So to has the code in the SolarSystem script which positioned our planets (I have created a new method which does this called PlanetPosition).
  • SpaceObjects contains the code to create the sphere objects for our stars and planets. This replaces the CreateSphereObject methods in both the Galaxy and SolarSystem scripts. Instead of being passed a star or planet the method is now passed a string for the object name.
  • All the code in the Galaxy and SolarSystem scripts has been updated to reflect the change in location of some of the methods.

If you have any specific questions on the changes or any trouble implementing the changes in the project let me know in the comments and I will help you out :).

I will put a small example of how we use the new scripts in part 6. It will show how we change the code which creates the star sphere object in the centre of our solar system (in the SolarSystem script). If you would like to have a go at doing this yourself before the next tutorial, go for it!



  1. This particular article does a lot of telling and not a lot of showing. If you just want people to download your code instead of writing their own you might as well just make an SDK rather than a tutorial.

    • Hi Vstdgmr, thanks for the comment. I wrote this article when i first started the tutorial back in 2016/beginning of 2017. I was still finding my feet as a tutorial writer. I have considered many times rewriting part 5 so that all this is done in that tutorial but I struggle to find the time. This is the only example in the entire series where something like this happens.

      Kind Regards

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.