2D Game Development: Customizing Speed

Thomas Kohut
2 min readJul 9, 2021

This article is an addendum to the Player Movement article and discusses how to customize the speed of an object.

Object moving at 5 speed

In order to change the speed of an object, we must add a number to be multiplied against the Vector3. For this, we will need to add a float variable to store the value of speed and then add it into Translation. For our purposes, we will set the speed to 5.

Implementation of the speed variable.

This works through multiplying the Vector controlling the movement with the float value stored in the _speed variable. It works similar to the distributive property in that _speed is multiplied against each value in the vector:

Multiplication of Vector3.right and _speed (ignores _hInput and Time.deltaTime)

Through this, the nonzero value of the vector is increased and the Time.deltaTime causes it to move that value per second. This use of speed customization allows for the developer to be able to create powerups focused around speed, which will be covered in a future article.

--

--