The State Switcher
Let's call the top-level objects in my game, which need to take player interaction and change states, let's call them Dynamic Objects (DynObj). For my purposes, anything that I decided should be animated together in Maya and imported as one piece is a DynObj. The "states" of the DynObj are a collection of attributes that change together. Ideally, I should be able to tell a DynObj to SwitchState(2); and the whole collection of things that need to happen will happen in concert, an animation will play and then stop on the right frame, a sound will play, lights will turn on, an item that was hidden behind a locked hatch is now interactable, a place you could not walk before is now traversable... etc. Anything whose "state" changes during gameplay will need some kind of controller. This is the state switcher.
The "TopHeavyBox" with the plank leaning against it was a top-level DynObj in the first Foxhunt, with its own bespoke script to control 3 states... 2 animations, 3 user manipulation colliders, some sounds, and the interactability/physics of the get-able item "plank" underneath. Say the user comes along and clicks on the front collider (1). The frontColl manipulator script will send a "triggered" message to the StateSwitcher, which will play a little jiggle animation and a sound. Nothing else will change, the box does not tip over if you push it from the front. States 0 and 1 are the same. No matter how many times you click the frontColl, the animation will play, but the box will stay in state 1.
Say you press the backColl (2). The box shakes with your exertion until you have held down long enough to topple it. A switch state has been triggered and a collection of things have to happen in concert: An animation plays showing the box toppling, the colliders 1 and 2 disable (you can't jiggle it or push it over again now that it's toppled), a sound plays, and the plank leaning against it (3) falls down and turns into a physical and manipulable item (4). A helpful "hole" (5) turns on in case we pick up the plank item and want to place it back where it belongs. We have gone from state 1 to state 2.
In the first Foxhunt, the "state switcher" was an ad-hoc alliance of an animation queuer, a one-off script that had to be manually-fed all the necessary colliders and item scripts, with a tacked-on sound player. I had not conceptualized DynObj yet. I'll tell you what I'm up to this time in the next post...
Leave a comment
Log in with itch.io to leave a comment.