Scripted, The Story of Events

So we’ve seen a lot of great art, great design work, and even learned about our new voice actors. Something I want to throw at you guys today is some great C# code from the depths of Unity.

The point of the script I’ll be showing off is to create scripted events in a game world. Basically we’ll be taking away the players ability to move so that we can lead our player the right way during critical parts of the game.
As far as actually doing it, all we need here to start is a class to handle the input. We’ll call this ‘InputMaker.’ Inside of this class we’re going to create a static instance of the class itself, so that we have something to call from.


public class InputMaker
{
    public static InputMaker myInput;
}

Great start right? So the next part is creating arrays that contain everything about our inputs for our game. In my case, because our character moves around the level, I ended up putting four different arrays here. You can look at the example below.

You’re also going to notice that I create a bool called playerInput. We’re going to use that to tell our game if the player is doing input, or if we are making input for the player!


string[] inputNames = {"ActionOne", "ActionTwo", "ActionThree"};
bool[] inputKeysOn = {false, false, false};

string[] movementInputNames = {"Horizontal", "Vertical"};
float[] movementValues = {0, 0};

int checkNum;

public bool playerInput = true;

Obviously these are all just an example, and go right below the static myInput we created before. To break everything down, the inputNames and movementInputNames are going to be lists of all of your inputs. The first one will be all of your button presses, so any keyboard buttons or controller button input you have. For the movement array, that’s going to be things like a joystick or a mouse that you have that needs to be moved around. That’s why we set the movementValues array to contain floats, because for us movement isn’t just on or off, we have different variants of speed that it can go at.

Now that we have these values, it is time to use them! What we’re going to do next is create some methods to be able to set whether or not we want these keys activated. That way in a script we’re able to call these methods and force our player to have some input.


public void SetKeyOn(string inputName)
{
    for(int i = 0; i < inputNames.length; i++)
    {
        if(inputNames[i] == inputName) checkNum = i;
    }

    inputKeysOn[checkNum] = true;
}

public void SetKeyOff(string inputName)
{
    for(int i = 0; i < inputNames.length; i++)
    {
        if(inputNames[i] == inputName) checkNum = i;
    }

    inputKeysOn[checkNum] = false;
}

public bool GetKeyOn(string inputName)
{
    for(int i = 0; i < inputNames.length; i++)
    {
        if(inputNames[i] == inputName) checkNum = i;
    }

    return inputKeysOn[checkNum];
}

So these three methods will work for the simple button presses, when using the float values you’re going to need to pass in float values for the Set, as well as return a float for the Get.

Now, something I recognize is that having a SetKeyOn AND SetKeyOff can seem a little redundant. However, it doesn’t affect runtime to badly, and as well it makes things easier to trace in the long run. We’ll be able to debug each thing separately.

The last big thing we’ll need to do before actually scripting our events is making changes to our player class. Here I’ll just show a simple example that hopefully you’ll be able to use in your own games! Here we’ll look at what happens when we’re trying to get input from our ‘ActionOne’ button being pressed. Normally it would look like what we have below here.


if(Input.GetButtonDown("ActionOne")
{
    //do stuff...
}

With our system the if statement is going to get a little bit longer, but we’ll have a larger area of control overall with our scripted events.


if((Input.GetButtonDown("ActionOne") && InputMaker.myInput.playerInput) || (InputMaker.myInput.GetKeyOn("ActionOne") && !InputMaker.myInput.playerInput))
{
    //do stuff...
}

So now we’re checking who is in control, and if any input is even trying to pass through anyway.

Now, the last thing we need is an actual script to make everything work! So create a simple MonoBehavior script, and inside here is what we do.


public class PressButton : MonoBehavior 
{
    int currentStep = 0; // This will keep track of what command needs to happen.
    float timePassed = 0; // This will give us time to pass, if needed.

    void Awake()
    {
         InputMaker.myInput.playerInput = false;
    }

    void Update()
    {
        time += Time.deltaTime; // We increment time, important for 
                                // movement commands.
        
        if(currentStep == 0) // Check the current step.
        {
            InputMaker.myInput.SetKeyOn("ActionOne"); // Here we set the action on.
            currentStep++; // And finally we increment the step, so that we can 
                           // use more steps moving forward!
        }
    }

}

And there you have it! You will now be able to use Unity to make some great scripted events of your own. I hope you were able to get some good information out of this post, and I’m excited for you to check out all of our scripted events inside of Building 37, being released this May. Here’s a sneak peak at one of our events the player will go through.

Untitled-1

– Austin Stewart, Lead Programmer

Advertisements

Finding our Voice

Ladies and Gentlemen, your Detective Ellis and Dr.Shannon!

 

 

(Sumner Musolf)                                 (Seth Berrier)

Hey guys and gals this is Jeremy Building 37’s own Game Design –Narrative lead with a special secret post regarding Building 37. You read right building 37 fans we hear at Two Hat Games have found those golden voices that will be our two main characters! Looking for just the right fit for our characters has been going on for about a month now and I am happy to say we have found our matches. We had a lot of people audition and it wasn’t an easy decision to make, yet we as a team are confident that we made the best choices regarding our characters personality. Congratulations to Sumner Musolf (Above Left) and University of Wisconsin – Stout’s very own Seth Berrier (Above Right). We here at Two Hat would also like to thank anyone and everyone who auditioned, it was a great pleasure to see so many interested people wanting to be a part of our game and we are thankful for your time and participation. The voices of Detective Ellis and Dr.Shannon is a huge aspect of our game, it helps engage players and full immerses them into our world and story.

If you don’t know about our characters here’s a little taste of what to expect: Detective Ellis, our main protagonist, is a hardened veteran who specializes in missing person cases. After the war he took his skill in finding people and started his own private investigations firm. Ellis has a slight distain for the way the world is after returning from war, and only goes after cases that peak his personal Interest. Now our Dr.Shannon is a brilliant scientist in the field of “odd” objects, but that was years ago, now after being left alone for many years he had been driven mad, and is now Ellis only help during his investigations. We are excited to bring you Building 37 in the upcoming months, and we hope you are excited to. We are hoping to get moving on with recording later this week and hope to have it in game soon! Thanks for reading, and remember… you didn’t hear this from us.