- Home /
Convert from m/s to m/fixedFrame
Is it possible to convert from Meters/Seconds to Meters/FixedFrame?
The thing is that I compute Velocity from the formula:
d = vi t + ((1 / 2) a t ^ 2) => vi = (d - ((1 / 2) a * t ^ 2)) / t, where t is in seconds, a is in m/s^2 and d is in meters
From this formula I get the velocity in Meters/Seconds. After this, I scale the velocity like this:
velocity *= Time.fixedDeltaTime (1)
I want to decelerate the velocity inside FixedUpdate() and there i have something like:
velocity += deceleration * Time.fixedDeltaTime (2)
Something tells me that the first line (1) is not accurate. My object stops much earlier from movement. Is there a corect way to do this conversion?
PS: I have my reasons why I do not use Unity's physics for this part of the project.
Edit: After some calculus, I figured out that the above lines do actually scale my velocity and acceleration, but there is another problem.
Here is an example:
Before convertion: velocity = 1, acceleration = -0.2 It would take me 5 frames to get to velocity = 0.
After convertion (Time.fixedDeltaTime = 0.02): velocity = 0.02, acceleration = 0.004 It would also take me 5 frames to get to velocity 0.
How do I get my velocity to 0 in the time I provide to the formula (the one from the very top of this post)? At this moment, each second of that time acts like a single frame after covertion.
Answer by tanoshimi · Sep 27, 2016 at 05:43 PM
If I've understood you correctly, don't you mean velocity /= Time.fixedDeltaTime
?
Not really. That value would mean how many times is my velocity bigger than fixedDeltaTime. What I want is the velocity scaled from m/s to m/fixedDeltaTime.
Then you must mean the reverse velocity *= Time.fixedDeltaTime
If your object moves 2 m/s and physics update rate is twice a second, Time.fixedDeltaTime
will be 0.5 and you'll get a result of "1".
That's more like "1m per FixedUpdate()" though
You are right, velocity *= Time.fixedDeltaTime is correct. But now I realize what the real problem is. I have updated my post, please check