Welcome to Repopulate DevLog 3!
Firstly, and I’ll mention this in the first few posts; I am writing this about 5 months into development. So, these first few posts are more retrospective, looking back at key stages up to here. Anyways, onto the post!
I had realised Gravity was going to be a challenge, but who am I to turn down a challenge? Half the reason I’m doing this is to learn and improve my gamedev skills and hopefully have something to show in job interviews. (Little present-day sidetrack note; the week I started working on this I actually had a job interview, mentioned this gravity system as a “what I’m doing right now” thing, and I actually got that job. Was it related? Who knows!)
Now, I don’t know much about centrifugal gravity, but I know the basic premise is that mass gets pulled towards the edge of a spinny thing. Like how your clothes are always plastered to the drum after the washing machine has finished. So, I figured the best approach was to just get my player’s position, get a “central” position, and apply a force pushing my player towards the centre. If I put this on a big sphere, it would effectively be like walking on a planet, with gravity always pulling towards the planets core. So, that’s what I did – and it worked great. I added an extra little bit to always rotate my player so their “feet” were always on the floor too, and realised my first problem. If I was walking along the middle of my ring (which was just the old flat 3D ring as a test object) it was fine, but as soon as I deviated my character started to… sway. It was like they were drunk.
My “gravity point” soon became a “gravity line”, which locked that sideways rotation by pulling to the closest point on a line instead of just one single point. I’m sure if I’d paid attention in Applied Mechanics at uni I could’ve done this in an afternoon but all in it took a bit longer, but I was really pleased with the result:
This was great! I’d made the player walk around the ring, and accidentally discovered orbital mechanics and slingshot techniques… but this wasn’t good enough. We still had the core to work with, so we can’t have the gravity affecting the centre too.
I implemented some distance checks to effectively create a custom bounding box aligned to my ring. In the video below, green means I’m within the area, and red means I’m out of it. When I’m “out of gravity”, momentum is maintained so I can just drift through “space”.
Great! All done. Whoops, we forgot how centrifugal force works… after sending that video to my friends. I added a toggle for “invert gravity”. Now the central point pushes you away instead of pulling you in and you walk on the correct side too! I’m just going to say it was for debugging the space movement and pretend it was all intentional all along.
Next up, I worked on a few more types of gravity. This was my “gravity line”, and I already had a “gravity point” that I’d made along the way. As well as those, I needed a gravity plane (flat gravity for within the modules), and I needed to decide how the central pillar and “front” of the ship should work. I decided the central pillar should be treating the rear ring as the “bottom” and front ring as the “top”, making it stacked like in the previous two designs – so I made a cylindrical gravity area for this too.
For the front, I came up with a few different ideas on the shape. I made a rough blockout of the whole ship in Maya with some example rings attached, and tried to decide on a front design. I liked the idea of being able to look out and see space ahead of you, so after a few iterations I settled on a domed front with a hexagonal floor. I used the gravity planes for each floor to avoid the sway effect from my first rings and it worked relatively well.
After taking a break for a couple of days, I decided I actually didn’t like that hexagonal floor. It felt very enclosed and claustrophobic for what I wanted as a bridge area, and so I made a slight change.
Instead of having that hexagonal floor, which was perpendicular to the rest of the ship’s core, I instead had a flat floor with the dome above you. There were windows all around, and the dome above gave a great, unobstructed view of space. I quickly added the skybox from Protect Sarius and a free Earth from the Unity asset store to see how things looked in game:
So! With that I had decided on the rough layout of my ship/station, at least in terms of where things are relative to one another and their orientation. Now it was back to updating game logic to work in my new layout. The building grid took a few minutes; rotation was being really strange for a while but my old friend ChatGPT and me put our heads together and eventually got it sorted.
Now, how do we actually get around this ship?