Lots more prep work today for what is now becoming more of an alpha composite scene that a single component function test. I prefabed the player game object and added a constructor script to it that was based on the one from the previous scene. The Player constructor class will control all things belonging to the player. I’m even considering tracking the forces affecting the player within its constructor. The idea is to differentiate between forces of gravity affecting a player and the force added by player movement so that each force can be balanced as needed.

I created a scene controller script that subscribes to actions triggered by the Player constructor. I’ll need to keep track of when players are added and removed without constantly counting in FixedUpdate().

I began to remake my gravity controller script by breaking its AddGravity() function into a bunch of smaller functions. I’m well aware that as this project’s complexity increases, my code will become harder to follow unless I organize before I build.

Even with that in mind, I still managed to get ahead of myself. I never found out if my code works when more than two objects experience each other’s gravity simultaneously. The good news is that I already have everything set up in the previous scene to test out that functionality. I’ll be returning to scene 3, which I more aptly renamed “Gravity Attraction”, before I do anything else in scene 4, which I’ll probably rename to “Alpha Test” by the look of things.

One more note: I disabled “Auto Refresh” in project preferences, which now means I have to hit Ctrl+R whenever I want to update my project’s assets. This is nice because now Unity doesn’t automatically reload when I update one of my scripts.


Tags: unity gamedev physics scripting refactoring