Postmortem
Though seemingly straightforward, this project did not come without its own grievances.
Due to my reference video being quite old, the code came a little broken and needed to be reconfigured. Therefore, I had to tinker around with it to figure out how to adapt it to the unity engine of seven years later.
This meant that I had to figure out how a normal 3d character controller was set up– which consisted of a camera and a capsule in an empty group. The group was assigned a rigid body and then I would attach the character movement mechanics into this script.
As this game was all about the character's ability to switch gravity and hop between planets, the gravity toggle that came with the rigidbody component was removed. Instead, we implemented our own faux gravity using the calculation of the distance of the player on the planet's surface to the planet's core and rotated the player angularly based on it per update.
I configured the movement so that the player is able to press space to jump and shift to run in addition to walking normally. If the player were to hold jump, they would begin propelling off of the planet slowly but would fall back into the planet's gravity if the planet's orbit point was not exceeded.
This took a few tries to get right, however, as I learned that my code uses the old legacy input method, and I ended up swapping the player input over to the old input manager.
Next, I made it so that if the gravitational pull of the planet is exceeded, the game will begin to calculate the closest planet to the player excluding the one the player has just exited the orbital pull of(which is achieved using tags). Then, it will begin to pull the player controller towards that planet. As the player begins approaching the planet, a different method will rotate the player character towards the alignment of the planet so that we will land with our feet planted to the ground.
For the spawner mechanic, the game would also take the center point of the planet and spawn random objects on the surface of the planets using the radius of the planet as a guide.
By tweaking the radius, I was able to create the illusions of asteroids orbiting the planets, which made the game a little more challenging to navigate.
With the main mechanic of the game done, I just needed to program in the win and lose conditions of the player, which was touching reaching the green planet and touching the asteroids respectively.
Then, I replaced all of the materials with slightly nicer looking ones and changed the hdri of the sky, which was about it for the game.
While making the game, the weirdest part about it was the code, which did not work in the beginning, but suddenly started working once I put in some print statements to troubleshoot the code. Another thing that went wrong was the gravitational pull of the planet.
For some reason, the code began taking in the diameter of the planets instead of the radius, which caused everything to be twice the distance away from the planets. This baffled me for a long time, as I was hung up on the orbital pull of the planet. I was saved by a kind saviour in the comments of the youtube video from 5 years ago, who pointed me in the right direction.
Leave a comment
Log in with itch.io to leave a comment.