2D Game Development: Customizing Speed
This article is an addendum to the Player Movement article and discusses how to customize the speed of an object.
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.
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:
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.