- Home /
How to apply friction independent of framerate?
Before anything else: Character controllers, not rigidbodies. I've been testing out the time it takes to reach a certain distance while my friction function is enabled at different framerates, and I have come up with some interesting results. My friction function is quite straight forwards: Multiply the player's velocity by a value each physics update. Since it runs in fixedUpdate, this means it should be framerate independent, right? It's only multiplying the velocity by a fixed amount a fixed number of times each frame- but the issue is, that my character controller does not seem to be moving independent of framerate- it simply isn't the case with my testing.
Unfortunately, I am not exactly sure WHY that is the case, because by all means, I should be getting a consistent standard deviation between framerates with this function. So, my ultimate question is: How do you appropriately create framerate-independent friction for a character controller? I am not looking to debug my own code, I just need to know if what I am doing lines up with what I SHOULD be doing. Should I be using a different mathematical approximation, or different method such as making use of Mathf.pow()?
Answer by $$anonymous$$ · Nov 11, 2020 at 10:45 AM
While it's true FixedUpdate runs a constant amount of times each second, the calculations performed in it still take time, so it's not frame rate independent. To make it frame rate independent you have to multiply the operation in it, in this case, multiplication, by Time.fixedDeltaTime.
Interesting. I wasn't aware of this; I also found a weird line in my code that confused me because it basically said a += b *= c, which I wasn't aware was legal code. I must have put an extra = sign in by accident somehow. With this info I should be able to fix my friction code.
Your answer
Follow this Question
Related Questions
Player Control. Roller Ball with Cube Acceleration. 1 Answer
Click to move a character in a terrain 1 Answer
Why is my character controller moving in unrelated directions? 1 Answer
rigidbody friction problem....HELP!! 1 Answer
Turning a rigidbody controller into a character controller (almost) 1 Answer