Objective: Add Player Tilt Movements and Speed Thrusters
In the previous articles, I have been updating parts of my 2.5D Shooter project. In this article, I am going to update the player movement slightly to show a tilt effect when moving forward and backward on screen. I will also show a thruster effect on the player craft and add a speed up.
I will start with the forward movement. In the Player C# script, I want to start with three variables to store the original rotation, the forward tilt rotation, and the back tilt rotation.
For the forward tilt, I will use Quaternion.RotateTowards and transition between the original and forward rotation, then I will add a 1 second pause before transitioning back to the original rotation.
I will use a similar pattern when the player moves backwards. For the neutral position, I will just use the saved player rotation.
In the Player movement script, I will check the horizontal movement for when the player is advancing forward or moving backward to show the tilt effect.
Now, let’s see this in action.
For the player speed up, I will create an empty object and store a small sprite to set active when pressing the Shift button. I’ll add 50% speed up to the player.
For the thruster sprite animation, I simply recorded some changes to the scale factor.
I added the shift button to one of the Player InputActions.
In the Player script, I got a reference to the child game object. To get a reference, I used transform.GetChild().
In the Player Update method, I check for the speed button, and set the thruster active and inactive and change the player speed.
Now, here are the results. I can probably refine it even more and restrict the thrusters from working when moving backwards, but in any event, it is working.
Thank you for your time!