Mobile Player Setup (part 5)

Adding Speed to the player movement

Now that we have optimized the jump mechanic we can proceed to adding faster speed to our player movement.

Objective: Adding a speed variable to our player movement

Start by giving an float handle for the speed variable. Then we are going to apply the speed variable to our movement calculations. By adding a serialized field on top of the speed value we can adjust it quickly within the Inspector.

In the movement method we can create a new float variable called “Direction” which will equal to the movement input multiplied by the speed variable.

Then in the velocity calculation we need to replace the new Vector2 movement with the new “Direction” value.

Back in Unity we can see that the speed variable is visible within the Script Inspector. The player now should have an increase in movement speed.