
You ever want to try something that could completely break your project if you mess up?
I thought it'd be cool to have gravity relative whatever direction I decide it to be.
I never dared to make such system as my project wasn't made with changing gravity in mind.
And I knew if I decided to do it anyway I would have to delete like half the code.
Removing features just for one experimental idea is a bit ridiculous.
However after some thinking what more I could do with this project I decided to give it a shot.
After all if it failed I have back-ups anyway.
I first did some experiments in a test project and it was extremely painful and confusing.
I figured I would base the gravity of the objects collision normal.
And while that somewhat worked, it caused more issues then it solved.
I gave up like 5 times in 1 day trying to make it work.
Anyway I gave up and looked up a youtube video to see if someone else had already tried this idea.
I found a video and this guy said to make the gravity relative to a point in space inside the object.
Such a simple solution, yet so effective.
I tried it and it worked mostly perfectly.
I did some tweaks to it so it also keeps flat surfaces in mind before applying gravity.
The hard part was translating that test project to the main project.
As expected I had to delete like half the code, so much so that now the animations don't work anymore.
But for some reason it kept failing.
While the gravity worked perfectly fine, the camera just hated me.
It did not want to cooperate.
Normally I wouldn't be to worried about the camera.
But since the movement in this project is directly tied to the camera it was import to make it work.
I almost considered giving up.
Then I decided to take a closer look at why exactly the camera was behaving like a drunk.
Turns out there was 1 line of code in the camera script that was the cause of my issues.
A line a didn't even remember putting in.
After removing that line the code suddenly worked as great as I could have ever hoped for.
VICTORY!! 🥳
While I may not have working animations and other removed features,
this new gravity mechanic makes it well up for it.
I can now walk around planets and other objects.
This system is very dynamic too.
I can jump from one planet to the next and have the gravity change with it.
This will give me so many possibilities for level design.
I am already thinking about a solar system level.
Even if I failed this little experiment I would still consider it a overall net positive.
As this allowed me to go through my old code and do some cleaning up.
I wanted to untangle my spaghetti for a very long time, but never felt like it. 🍝
Maybe I'll replay Mario Galaxy for some more level inspiration.