Unity — Implementing a thruster effect

Benjamin Calvin
3 min readOct 21, 2021

--

Objective: Implement a visual effect and additional speed to give the feel of a boost.

  1. Create the gameobject, attach it to the Player object, and animate it
  2. Script out the ability to press left shift to enable both an increase in speed AND a visual thrust effect.
  3. Attach the thruster object to the player for script access.

Drag and drop the first one in the Hierarchy view. Rename it Thruster. Resize the sprite scale X and Y to 0.5. Add it to the Player object as a child object. Resize the thruster sprite in the Scene view below the ship. As a child object and positioned properly it should look like this:

Now all those Thruster sprites will help give the thruster an animated effect. Click on the Thruster object, go to Window > Animation > Animation. Create a new Animation, save it as Thruster_anim in the Animation folder created prior. Highlight all thruster sprites, drag and drop them into the animation window. The effect will look like this. For now, in the editor, disable the child object.

  1. ̶C̶r̶e̶a̶t̶e̶ ̶t̶h̶e̶ ̶g̶a̶m̶e̶o̶b̶j̶e̶c̶t̶,̶ ̶a̶t̶t̶a̶c̶h̶ ̶i̶t̶ ̶t̶o̶ ̶t̶h̶e̶ ̶P̶l̶a̶y̶e̶r̶ ̶o̶b̶j̶e̶c̶t̶,̶ ̶a̶n̶d̶ ̶a̶n̶i̶m̶a̶t̶e̶ ̶i̶t̶
  2. Script out the ability to press left shift to enable both an increase in speed AND a visual thrust effect.
  3. Attach the thruster object to the player for script access.
  • Open the Player script, create a private GameObject _thruster; Ensure you serialize the field or you won’t be able to attach the thruster object later. The _speed variable has been already created for the player movement section.
  • Call the Thrusters(); method in Update() so the game checks this variable every frame per second.
  • Create a Thrusters method.
  • Create branching statements: To tell the game that left shift is pressed down or not. GetKeyDown will only activate when pressed, if held down it will ignore it. GetKey is what you use to get a key that is being held for whatever reason.
  • Add a null check in there to ensure the object is available.
  • Set the speed to the boost of your choice, I decided a slight increase. It is modifying the _speed variable. This is already coded into the player movement method here.
  • transform.Translate(direction * (_speed * _speedMultiplier * Time.deltaTime));
  • _thruster.SetActive(true), this will activate the game object whenever LeftShift is pressed and held.
  • the else statement ensures the defaults are enforced.
  1. ̶C̶r̶e̶a̶t̶e̶ ̶t̶h̶e̶ ̶g̶a̶m̶e̶o̶b̶j̶e̶c̶t̶,̶ ̶a̶t̶t̶a̶c̶h̶ ̶i̶t̶ ̶t̶o̶ ̶t̶h̶e̶ ̶P̶l̶a̶y̶e̶r̶ ̶o̶b̶j̶e̶c̶t̶,̶ ̶a̶n̶d̶ ̶a̶n̶i̶m̶a̶t̶e̶ ̶i̶t̶
  2. ̶S̶c̶r̶i̶p̶t̶ ̶o̶u̶t̶ ̶t̶h̶e̶ ̶a̶b̶i̶l̶i̶t̶y̶ ̶t̶o̶ ̶p̶r̶e̶s̶s̶ ̶l̶e̶f̶t̶ ̶s̶h̶i̶f̶t̶ ̶t̶o̶ ̶e̶n̶a̶b̶l̶e̶ ̶b̶o̶t̶h̶ ̶a̶n̶ ̶i̶n̶c̶r̶e̶a̶s̶e̶ ̶i̶n̶ ̶s̶p̶e̶e̶d̶ ̶A̶N̶D̶ ̶a̶ ̶v̶i̶s̶u̶a̶l̶ ̶t̶h̶r̶u̶s̶t̶ ̶e̶f̶f̶e̶c̶t̶.̶
  3. Attach the thruster object to the player for script access.

Finally, attach the thruster child object to the variable created earlier through the Unity editor.

--

--

Benjamin Calvin

Dedicated and motivated individual learning programming and sharing my discoveries with you.