Hi, i’ve encountered a problem. Currently in my project i have Character Controller script which handles basic movements and some melee attacks of my character. With all the code, it’s getting too confusing to handle.
What I need (or at least think i need) is some kind of moves/damage class in separate script. This script should contain moves and also deal the damage to enemies. What is troublesome in this approach is that I’m using different kind of bools to mark the states of attacks, jumping, crouching etc in the character controller script.
So is this a good way or is there a better way? That’s what im trying to figure out. How to make adding different kind of moves that include moving character, checking distance to enemies, adding damage to enemies. I’m not looking for code, just explanation or suggestions how to approach this?
“How to split functionality” is always a welcome debate topic in any programmer discussion. Here are my 2 most important cents:
When starting the design from scratch, try to split along structure, not data. That means, make separate scripts for handling animation, scripts for additional effects, scripts for sounds etc. Do not split scripts by “the roundkick attack and everything that belongs to roundkick” and “the forward slash and everything with the forward slash” etc…
And now the single most important advice: Review your design along the way! You almost never ever get it right in the first try anyway. Splitting and reuniting parts of your code is totally normal daily work and not a sign of “too few thinking ahead”. So if you find two scripts that constantly need each other, join them. If you find one script that has two or more sets of mostly disjunct variables & functions (one set of functions almost only uses this variables, another set almost only those) then this is a good sign that you should split the script.
Thank you, that was very informative! As I’m interested in programming and have programmed for short time this was very interesting.
So, I could deal with Input and movement in one script and call animations from another script based on input. Then i would have moves script, which has Input and movement needed for attacks(for example aerial attacks need that player is on the air). Problem is, if the jumping state is in character controller, i need to get the state from there to be able to do aerial move when on air and not in ground… static variables maybe?
Also I’ve got no idea what to do with damage. Different strikes deal damage differently. Some attacks include jumping from air to ground and dealing damage to multiple enemies etc. Some attacks have minimun and maximum damage and randomize the totaldmg from that.
So I need a way to separate damage dealing and the actual move+animation. I try to make something, thank you for your answer.