Updating the Player Movement
I created a primitive Space Fighter model that I’ll use for the Player Prototype and gave it a simple engine effect with a Particle System. Additionally I started tweaking the Player Movement method allowing the player to tilt towards a direction when given input conditions are met.
Objective:
During movement, tilt a Transform smoothly from one side to the other, corresponding to the user input.
Solution:
You can also achieve the desired effect by using Animations but in this case I decided to add it to our Player script by changing the movement behaviour using a Quaternion.Slerp.
Logic:
Let’s have a a quick look at the declaration for Quaternion.Slerp and how we can use it to smoothly interpolate from point a to b.
In our case we want to update the player transform rotation when horizontal movement input is detected. In the Player Movement method we apply it like this;
So we have to define a target rotation we want to rotate towards. Let’s say that the Player is in its default position;
Add a private member variable that is responsible for the transforms maximum tilt angle.
Then add a local variable that allows us to modify our target rotation by subtracting it from the Y axis.
Now we smoothly interpolate to the new rotation based on user input.
Here is an overview of the current Player Movement method.