Galaxy Shooter: Speed Boosting Thrusters

In this quick article I’ll show how I added the ability to press the left shift key for a boost from the thrusters in my 2D Space Shooter Unity game. (Any other key and/or button can also easily be used with the new input system)

I’m using the new input system, you can see how I have it setup in my previous article.

I first went to my Input_Manager in the hierarchy, then in my Player Input component I double clicked my Controls InputActionAsset to open it.

I then clicked the + to the right of Actions and created a new one named “Thrusters” and added a binding for the left shift key. Checked the box for Keyboard&Mouse control scheme.

Now in my Player class I get an error that the OnThrusters method has not been implemented, clicked the lightbulb icon at the error underlining Controls.IPlayerActions in Visual Studio and implemented it, this adds the method to the bottom of the script.

I also added a private float variable for thrusters boosted speed multiplier.

Now instead of messing with my CalculateMovement() method I simply modify my _speed variable in my OnThrusters method by setting _speed equal to _initialSpeed multiplied by my _thrustersBoostedSpeedMultiplier when the Action is started(key has been pressed) and then reset the _speed to the _initialSpeed when the Action has been canceled (key has been released).

Last but not least don’t forget connect it all by dragging your Player into the events section in your Input_Manager’s Player Input component Events>Player section and select the OnThrusters method in your Player class. I spent some time wondering why nothing was working when I forgot to do this.

In a future article I’ll be reworking it to work with a thrusters meter bar in the UI that will limit the thrusters use to a certain amount of time before they need to be recharged.

--

--

--

Unity Developer/C# Programmer for VR, 2d,3d Games and other Immersive Interactive Experiences

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Utilities system must support

4 Really Small Things That Say a Lot about You Hint: It’s not what you say.

A Bootcamp Grad’s Guide to Technical Interview Prep

Migrate Odoo to HubSpot CRM to Get More Profit (2018) — Data2CRM

My iTerm2 Setup

13 sites de cursos de TI

Highlighting columns in Pandas DataFrame

State of Matterless #15

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Crippen

Andrew Crippen

Unity Developer/C# Programmer for VR, 2d,3d Games and other Immersive Interactive Experiences

More from Medium

Light her up — Adding emissions to your game objects using photoshop and blender

Unity Tutorial — Toon Shade in HLSL

Benefits of Prototyping with Cubes

Platformer: Elevator