I want to write a function to enable a Character to transition from running to walking (40% of the movement speed), but I’ve run into a problem. What’s going on?
Here, we double the speed while sprinting. (Since the values 500 and 250 are fixed you can also adjust the increase by replacing the values. You can also replace the placement of the higher and lower values along with the default value of max walk speed to reverse it like how you wanned it to be in your snippet.)
Now let’s analyze your snippet.
Note that this:
is unnecessary since you can just set it to 240. And no, expanding the calculation doesn’t solve the magical numbers issue. But maybe you were planning to replace the value 600 with a variable in the future.
Also note that having a double for 0.4 there is also unnecessary, if you do plan to multiply a variable in the future keep in mind to avoid unnecessary conversions and multiply it with another float like 0.4f. (Doesn’t matter that much tho tbh)
Moving on,
You’re also not using your parameter by doing this:
And lastly,
You don’t put semicolons at the end of your function definitions!
When it comes to the actual issue, I believe you don’t have a function declaration in your header file, or you might also not be triggering the function.
If you keep encountering issues tho, you can get back to us providing the full code