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

Player Script:

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.