Adding Visual Effects using Scale
Make the Player feel like moving faster
To create this effect we will be change the scale of our thruster game object. This is a follow up to the previous article where we created a sprint function.
The function we will be using is:
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do…
In our game we got 2 states for speed increases. When the sprint is used and when the powerup speed boost is active. Important to keep in mind is they can be stacked. Sprint can be used while speed powerup is active.
Rescale Thruster with Code
Put the following code at the top of the script. These are the value to adjust the scale and the position during the speed increase.
//speed vfx config
private Vector3 _scaleChange = new Vector3(0.2f, 0.4f, 0);
private Vector3 _posChange = new Vector3(0, -0.25f, 0);
This code is the actual modifying of the scale and adjusting the position.
_speed *= _sprintModifier;
_thruster.transform.localScale += _scaleChange;
_thruster.transform.position += _posChange;
else if (Input.GetButtonUp("Fire3"))
_speed /= _sprintModifier;
_thruster.transform.localScale -= _scaleChange;
_thruster.transform.position -= _posChange;
We repeat the same logic for our powerup speed boost.
Child gameobject position change values affected by Parent Scale
When using the _posChange on a gameobject that is a child, the values are affected by the scale of the parent gameobject.
Scale Parent: 0.5f
Child pos change in script: -0.625f
Actual value pos change: -1.25f