Using Time.deltaTime but acceleration is still tied to framerate
Hello!
I'm trying to make a character that rolls when the player holds down the forward button. I'm taking their input in Update and then modifying their velocity in FixedUpdate.
So for example, here's how I calculate the X velocity:
x = Mathf.Clamp(rb.velocity.x + realForward.x * Time.deltaTime * _modifiedRollSpeed * rollInput,
_modifiedNegativeSpeed * Mathf.Abs(realForward.x),
_modifiedPositiveSpeed * Mathf.Abs(realForward.x));
Wherein rb.velocity.x is the current X velocity of the Rigidbody.
realForward.x is the X direction of the "real" forward direction (this is to handle what direction forward is regardless of how the player is rotated because of the rolling mechanic)
Time.deltaTime is self-explanatory
_modifiedRollSpeed is a speed I change through several game mechanics
rollInput is the positive/negative input gained via Update and the Input system
Then I clamp it to make sure the player can't go too fast and multiply if by the realForward.x to ensure every direction has an equal maximum.
All of this works fantastically when I run at unlimited FPS (I usually run around 140fps in editor). But when I limit the app to 30fps via Application.targetFrameRate, suddenly the player's acceleration is incredibly slowed down. It takes minutes to reach max speed, not seconds.
I've tried using Time.fixedDeltaTime as well as setting another float to Time.deltaTime within Update and using that instead, all to no avail. The player is always extremely slow at 30fps, even though Time.deltaTime should be accounting for this.
Any ideas on what could be the problem or how to fix it?
Ik this is old but im having the exact same problem. Have you found a solution?
Answer by PersonMon · Nov 28, 2020 at 10:13 PM
http://answers.unity.com/answers/416370/view.html
This worked for me
Your answer
Follow this Question
Related Questions
Does FIxedUpdate get called every 0.02 seconds? 2 Answers
Game is too fast in Mobile 1 Answer
Is it even necessary to multiply by Time.deltatime in fixedupdate 3 Answers
Physics after build feel different vs In-Editor (Time.deltaTime) 1 Answer
Physics inconsistent even when using FixedUpdate() or Time.DeltaTime() 0 Answers