Updating the Player Movement

Gert Coppens
Nerd For Tech
Published in
3 min readAug 6, 2021

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.

A quaternion spherically interpolated between quaternions a and 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;

current rotation, towards rotation, smooth time

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.

Mathf.Round returns float f rounded to the nearest integer.

Now we smoothly interpolate to the new rotation based on user input.

Here is an overview of the current Player Movement method.

Previous | Next

--

--

Gert Coppens
Nerd For Tech

Software Engineer — Unity Game and Application Developer