The way I've written this actually makes use of the sine function! Whenever the player presses shift (keyboard) or X (x-box controller), a timer counting at 10x real-time is started and Hensen's movement speed is increased with respect to the sine of the timer's value. The timer ends at Pi seconds.
I chose to do it this way because using the sine function as a multiplier for the increase in movement speed has the effect of blending the dash in smoothly so long as my timer starts at 0 and is stopped at Pi (because sine 0 and sine Pi both equal 0 and sine anything between those two values is a positive number <= 1). In order to modify the duration of the dash or the speed of the dash, I can simply multiply Time.deltaTime when incrementing the timer or multiply the Mathf.Sin() call respectively.
I then capped the movement speed increase to a value I can modify from the inspector which has the effect of making it so increasing the multiplier on the Sin call beyond that speed increase cap, rather than increasing the movement speed increase during the dash, increases what you could call the abruptness of the dash.
Much like everything else in my PlayerController script, the dash is triggered in the Update method based on the player's input read from the InputManager and the HandleDash method only modifies values related to Hensen's movement, which are used in FixedUpdate where the actual movement of the character in the scene is performed.
One thing I'm thinking about adding to this is actual variables for the dash duration and dash abruptness (aka the multiplier on the Sin call) that I can modify from the inspector. The dash abruptness is fine, I'd just need to do a bit of planning for dash duration. I know there is a way to normalize the duration into seconds, I just need to work out algebraically what the formula is for this and then implement that into my code. I also plan on adding some effects for the dash to make it easier to tell when you're dashing which is an entire other task.
Thanks for reading!
0 comments