FSGD Final Project Week 9: Gamepad, Sprint, and New Attack

This week I really wanted to get a feature from the B features of our feature list given none of them had been added yet. I decided on getting Dualshock 4 support because it seemed like it’d be a lot easier to play with a controller than a mouse and keyboard.

Before I added controller support though, I decided to get a sprint working. The sprint is interesting because when the player holds down shift and moves forward (the only direction that you can sprint), the player’s max velocity increases, so that when the movement script is adding a force to the player, it can now speed up past its old max velocity.

Along with the sprint, I also had to hook it up with Sam’s sprint bar that she made, so the player wouldn’t be able to sprint when the bar was empty. I stupidly didn’t ask her to help me with it, and I ended up setting up my own functionality to implement it. She didn’t like that though, so she ended up using her code and then adding more code to make our two classes work together.

An interesting thing about the sprint is that I wanted it to be like Rocket League’s: turbo boost for a while until you enter an even faster state where you can then destroy enemies by hitting them. I wanted this because the attack felt cheap the way I made it earlier (collide with someone and click F). Instead, I wanted it to be harder. So after 2 seconds of sprinting, you go into a charge state where you run even faster. If you hit someone with a ball during this time, they drop it.

Honestly, one of the harder parts of this was getting the sounds to work correctly. I made two sounds (sped up version of the person walking), and they would play during their respective time. My problem came from having to stop the previous sound and playing the new one. Luckily, I eventually did just that and it worked good. So far, this is the only feedback the player has of charging (the fastest paced footsteps of all three).

With the sprint and new attack out of the way, I decided to get controller support in. Luckily, DirectX has a toolkit that has a GamePad file that I could use to handle gamepad input. Interestingly enough, this class is really a wrapper for Xinput, which is class that handles input.

At first, I just tried dragging the Gamepad.h into the project, but it couldn’t find Xinput, which I didn’t have installed. I didn’t know where to find this, so I relooked into how I could get Gamepad working in the project. I found a tutorial that told me to add the whole DirectXTK project to the solution, and then to set up a reference in the project I wanted to use the toolkit in (as well as point towards the includes in the project settings). This way, I had the whole DirectX toolkit at my disposal just in case we needed to use it in the future.

Once this was out of the way, it was really easy to incorporate all the controls on the Dualshock 4. Unfortunately, Microsoft hates the Dualshock, so I have to trick my computer into thinking the Dualshock is an Xbox controller (I do this through Input Mapper).

In addition to this, I had to send all of the gamepad info from the client to the server. So I made new functions in the server and client files that would send/receive a message consisting of a char*. At the front of the message, the header, I did the size of the Gamepad State to indicate the message is a Gamepad State. Having such a generic function to send and receive messages is really easy to send structs because I can just cast the instance to a char* and send it. Then I switch on the header.

I managed to get a lot more done this week than last week given I didn’t have to work on documentation, and I’m glad that I managed to rework the attack into something less OP and got controller support as it’s fun to play with one.