RPG-ish Combat System

I’m having an issue properly executing a plan on how to accomplish my goal. What I have is a generic character controller that moves my character around the world, then under certain conditions, let’s call it a “random encounter” the player transitions from a character controller and into a combat controller. Instead of moving the player into a different scene and starting a combat sequence script that manages turns, attacks, random numbers etc, , I want to start the script at the time of the “random encounter” in the environment where they’re currently at.

What I’m struggling with is where do I put the script while it’s not in use. It’s a pretty big script to just be carrying around at all times on my player. I’ve been thinking of putting a “player controller manager” on the player that’s light weight and calls an instance of each of the character controllers when necessary. I have four different controllers planned, but only one is active at any given time.

Is this a viable method of managing the character controllers?

Just disable the controller scripts that you aren’t using. A disabled script incurs virtually no overhead.

Does disabling a script not load it into memory until it’s been called?

It’s loaded into memory, but it doesn’t do any processing (no Update, FixedUpdate, LateUpdate, OnGUI, etc.). Unless your script defines some massive data structures (e.g., float[ ][ ] myBigArray = new float[10000][10000]) the memory footprint should be fairly neglible, too.

Okay, now where would I store my three combat systems? These systems will be on the large size but it may not matter.

The first combat system is partly complete and only contains the results of each round of combat (hits, misses, why they missed, damage done, damage to armor, damage to player, animation commands, GUI updates, and a bunch of other crap). It runs on about 800 lines of code. Would this just ride around on my player along with the other two and just activate and deactivate as they’re needed?

That would work. You could also add a small manager script that uses GetComponent to get a reference to each controller script and ensures that only one is enabled at a time.

1 Like

I’ve always found when you’re dealing with systems that there are two approaches. I favor the first of the two.

First my definition of system is something that controls a whole part of a game. Character Control being one, defines anything having to do with player interaction with the character. As you’ve stated above, it can be quite tricky if you need different control mechanisms in one scene, so.

Method 1. I like to put all of the controls in one single script, and have types control what is active, and when. This allows for me to change controls almost instantly, and use the type change to trigger UI changes and other things, like animations, or scripts. Meaning… You’re walking in non combat mode, then all of a sudden wolf pops out of a bush, bool Combat changes from false to true; and based on that change UI, animations, and character behavior/movement controls change.

This would have completely different code for each system, say its a JRPG, but you want to walk around the map like its an RTS until that point, well at the point the battle starts, you’d just change the character controls from point and click movement to no movement, but control of the character through UI choices like ATTACK and USE SPELL. Meanwhile the game UI would change to match this because its all controlled by one bool value switch (Combat == true).

Pros : Having all the control systems in one script saves you from having to go from script to script to change small things, and acts like kind of a base for that entire game system.
Cons: If you’re bad at organizing script syntax and using comments, your going to have a bad time.

Method 2. Do the same idea as above, but split it into different scripts that are activated when modes change. Using a game manager script to do the switching.

Pros: Maybe more organizable?
Cons: I dont like this method.

But to answer your question, that would be refering to method 2 I think, and the best way to manage that is through a manager script/object that stores all the things that are either switched on or off at some point.

EDIT: Additionally since you typically only have one character control script running at a time, unless you’re really really using some expensive functions such as find object and other expensive operations I would not really worry about this being expensive in your game.

1 Like

“…unless you’re really really using some expensive functions such as find object and other expensive operations…”

If I’m going to create what I want to then yes, it’s going to get very expensive. I may never get to that point of creating the full game but I will need to snap to new targets on key press. Ideally I’d like to duplicate the swarm mechanic like Shadow of Mordor. The combat system I’m working on now is more of a turn based RPG with a very limited time to enter in your actions. The third system is like Shadow of the Colossus. None of these seem to share a lot of functionality and are going to be beasts to program but I’m up to the challenge.

I’m going to play safe and try a manager just for my sanity.

Yeah Sanity is key haha