Player Input: Where Should the Logic Be Held?

By: Matthew Steinhardt

Expanding on the Player Input

When creating our player character, we initially had the idea for all of the player interaction to take place within the third person view. This included the shooting, placing towers, and purchasing upgrades. However, as we discussed our idea more it became clear that a better view for building towers would be a top-down, wider angled, view.

The Problem

I set out to create player input controls to allow the player to seamlessly switch between a third person camera view and a top-down view. In this new "mode", the player got a much bigger picture of their surroundings. In addition, we made the cursor visible only while in this view to allow the player to easily interact with a familiar UI for placing buildings. However, there were a few problems.

The first problem was that controlling our character from a top-down view didn't feel good. It was clunky and there was no reason for the player character to be moving around while in this view either. This meant we would need a different set of movement controls while in the top-down view and some way to "reset" the camera back to the player character when the player wanted to swap between the two. Suddenly, I foresaw our player input logic becoming extremely messy very quickly.

The Solution

Two Input Modes: Two Pawns

I took a step back and decided that our two separate input "modes" deserved their own respective pawns. The top-down (aka "Building Mode") view did not need to concern itself with the player character, as we moved away from having the player character be directly controlled while in this mode. So, I created a new pawn with a floating movement component that, when possessed by the controller, would allow the player to smoothly glide around the map using the WASD keys.   

Moving the Logic

I moved the logic that listened for input events regarding view-switching into the player controller instead of the player character, where it originally was held. I then stored references in the controller to both the player character and the "Building Mode" pawn. All of the logic that was responsible for swapping they player between the two modes is now here. Not only did this clean up the messy code structure, it also allows us to easily refactor and swap out one pawn for another. If we decide we want a completely different set of controls in the "Building Mode", it's as easy as swapping the reference for said pawn in the controller. Modularity is cool!

Player Controller logic handling swapping between both modes

Comments

Popular posts from this blog

UI Polish

AI Navigation Problems - Yashwant Patel

Round End Cutscene Implementation