Objective #3: Convert Drone Controls

Gerald Clark
4 min readMay 11

--

This game has a drone in it. After blowing up the car an d hacking the laptop, you can fly a drone around. Currently this is being handled with the legacy input system. Lets convert it!

First step is to create a new Action Map for the drone controls. The reason is because currently the Player Action Map is enabled. We enabled that on start in the Player class. When you switch over to a new action map you need to remember to disable the previous one. If you don’t, in this case, while I fly the drone around the player model will still react to inputs.

As you can see here, in the Player class, in the OnEnable() I am registering some events. The Drone.onEnterFlightMode is the one I’m concerned with at the moment. What happens there though? If I highlight the onEnterFlightMode text and press f12 it will take me to the declaration of this event.

Oh nice! Its in the Drone script. You can also tell that because we are registering Drone.onEnterFlightMode. So obviously that event is being declared there. Lets check it out.

You can see here that a method called EnterFlightMode Invokes the onEnterFlightMode event. The EnterFlightMode() invokes the onEnterFlightMode event. This disables the controls for the player.

The EnterFlightMode method is called when a zone’s interaction criteria is met. This is handled through another set of events that I’ll eventually get around to explaining. For now, we know when the player controls have been disabled.

Now I have to enable the Drone Action Map. What better place to do this than the Drone script in the EnterFlightMode method?

Now lets checkout what we have going on with the drone’s movement.

Oh dear. We are checking for input on a key level… to me this is kinda hard to read. I get whats happening, but why do we need to make it hard? I’m going to set up a 1D axis for W and S keys and another for A and D keys. I’ll also assign the W and S action the left stick on the controller and the Right Stick will be assigned to the A and D keys.

Now, instead of reading a million lines of code we’ve got 3. Now that I’ve done this I realized I could probably use a 2D vector composite instead of a 1D Axis. Either Way this works. I also wanted to assign different sticks to these inputs, so I did it this way.

Now I’ll get into the turning.

This is checking for left and right arrow input. Sounds like I can use a 1D-Axis again!

This isn’t much LESS complicated, BUT now I’ve got some controller buttons assigned to this as well as keyboard buttons.

The drone can also change it’s height.

I’m going to use…. YOU GUESSED IT! A 1D Axis again!

Simply gonna check the float value of the input and perform the appropriate logic. I haven’t changed much here, but now I can easily add whatever key bindings I want.

Now all that’s left is to leave the flight mode. In Update() input for the escape key is being checked constantly. Lets just set up a simple button action and call the ExitFlightMode() in that performed action method.

You can also see here that the onExitFlightMode event is invoked. This gives control back to the player and disables the Drone Action Map.

Lovely! Now the unnecessary input check in update is gone, we have controller support, and this system is very robust and easy to add to and take away from.

One of the next tasks is to change the Forklift controls. My approach would be very similar to the drone, so I wont get super deep into that. I think the next article will cover a destructable box at the end of the game. It will have 2 different behaviors when I hold the interact button and when I press it.

See ya there!

--

--

Gerald Clark

Father Game Developer Music Composer Sound Designer