Hey all, sorry if this isn’t the right location to post this, and I apologize for the vague title, I’m really not sure what to call these.
Essentially I’m wondering what the best practices / design patterns are for handling and organizing what I’m calling Scripted sequences. A situation might be the following:
In an action-RPG style game the camera tracks the player as the player plays the game, however when the player hits certain triggers, control is disabled, the camera re centers to show some bad guys, and the main character and bad guys have a quick discussion (“I will destroy your world MUAHAHA”, etc.), including some animation. After the sequence, the camera is re-centered on the main character, and control is restored to continue the game.
OR something more simple. A 2d space shooter where the player has killed the local enemies at a waypoint and wants to “warp” to the next waypoint. In doing so, control is removed from the user, the ship centers itself towards the next way point and zooms off the screen. The screen fades to black, and when the screen fades back in, the player “warps” into frame at the next waypoint. Control is restored.
In my games there could be hundreds of these. Right now I have a simple game controller controlling the if / when it can happen as well as controlling the animations, all in one script. As I’m just making a mock-up / demo this isn’t a big deal, but it’s not scalable or well organized.
Is there a design pattern for this in large games? I could obviously invent one, but my google searching is failing me as the word “scripted” keeps giving me bad results.
Hey there, the title definitely isn’t vague at all. And it’s a very important topic regarding programming.
I suggest looking into Youtube channels such as Brackeys and Infallible Code to listen in on those subjects.
Most important uses are Inheritance, using of interfaces, scriptable objects and code refactoring.
What you describe above, “Right now I have a simple game controller controlling the if / when it can happen as well as controlling the animations, all in one script.” Is called a monolithic class. It’s a term used for a class that has too many cluttered responsibilities. Organize and plan your code carefully, break it apart into separate components, and you’ll be able to easily get control over each GameObject.
Hey thanks for the response. I guess my question was more centered around if anyone had any frameworks for this (self made or otherwise) that might be better than my solution. I realize what I’m doing is incorrect. In the past in production code I’ve created several subclasses of a “Cutscene” object, which had a tick() function which was executed at the game controller update. The game controller is responsible for responding to events and triggers that would trigger a cutscene, and that cutscene takes over the whole of the scene.
The problem is two fold: first it takes some effort to ensure that the state is correct when the cutscene ends. Second, it’s entirely driven by code and I’m wondering if there’s a better way to do this in data (like XML), or if there’s a better way to structure it so I can easily wire it together (like behavior trees are way easier to wire together and modify in code than state machines for example).
I will certianly check out the youtube channels you recommended.