Hi there!
I’m making my first “serious” attempt to make a game in Unity. Along the way, i’m learning how to improve my basic C# programming skills, getting to know the particular ways in which Unity behaves, etc.
I’ve managed to create a isKinematic movement for my player, also my own physics collision system for static colliders (checking what’s below and above the player, to the sides, etc) and moving platforms (i can stay on the platform and move and even jump quite well).
It has taken my a lot of time to do this, about 4 weeks since I started working on my free time after work and weekends, but i’m happy to have kept progressing little by little by solving unforeseen challenges (for me they are =)).
So now comes the question:
My player script starts getting longer and longer. There i have the movement and collision system, and it’s there were i check if the raycasts have hit any other object by asking their tag (i’m not using onTrigger functions as I prefer to go for preventive physics) and how the player should act.
As you may imagine, or maybe it’s my lack of expertise in programming, i have LOTS of bools for any given situation. Some examples:
- if player is not grounded and hits something when start jumping.
- the same for when the player is going down on his jump.
- check if I hit a static collider with the head and if it’s so do not jump the maxJumpHeigh but only a portion.
- if it’s not grounded and i hitted a moving platform while the platform is going up.
- the same for when is going down.
- etc, etc, etc.
When i have a bug or wrong behaviour with movement or collisions, i need to go through all these bools, and each small change it’s painful as there are many bool combinations i must take into account.
- So, is there a way to keep the bools organized, kind of a bool manager in a separate script?
- Do you also use so many bools in your code, or i’m I doing something wrong? Is this the price one must have to pay to have a solid movement and collision system and be able to handle the most complex gameplay combinations?
- If I create so many scripts to make things more modular, won’t it be too painful and too verbose to refer to so many bools (and variables in general) in the shape of thisClassScript.thisMethod.thisVariable?
I’ve never used any game manager and to be honest I don’t know where and how to start using it. I keep reading about the topic and also the dangers of using global static variables, (there should be only a few in the total code to follow encapsulation or proper OOP methodology they say)… i’ve never used delegates or virtual functions either yet (maybe I’m having the need but I haven’t realize it yet!)… i’m wondering if things are getting more complicated because I actually yet don’t understand fully how OOP works and all the possible solutions C# offers.
Any advice for the bools organization, links you think can clear out my existencial doubts (some of those are too complex for beginners) will be more than welcome. =)