How does unity handle the deceleratikon of rigidbodies on impacts? I did some testing.
So far all ive done is crank the fixed timestep to 0.01, and i fired a gravityless-ball v ery slowly at a kinematic wall at a velocity of Vector3.forward (so the magnitude of velocity is 1.0)
, and tracked the magnitude of its velocity during the impact:
in these debug messages, the leftmost number is the magnitude of velocity, and the right one is the current frame number (number of fixedupdate calls since start of running). note also i added a conditional to not display message when the velocity was >=1 or = 0
As can be seen here, it takes about 7 frames to lose most of its speed, but then gets stuck at 8.642675E-06 until frame 393 (15 frames)
I need some help making sense of this. How is unity doing this gradual deceleration, is there a deterministic pattern to it ? And why does it get stuck at some very low value for 15 frames (0.15 seconds) before finally coming to rest?
i’ve been doing some testing, i made this simple test harness script
using UnityEngine;
using System.Collections;
using System.Diagnostics;
public class VelocityMonitor : MonoBehaviour
{
int i = 0;
public float j;
float mag =10f;
Stopwatch timer = new Stopwatch();
void Start()
{
rigidbody.velocity = Vector3.forward*mag;
}
void FixedUpdate()
{
j = rigidbody.velocity.magnitude;
if (j < mag && j > 0.0001f)
{
timer.Start();
print(j + " num " + i);
}
else if (timer.IsRunning)
{
timer.Stop();
print("Total Time Taken to stop " + timer.Elapsed.TotalSeconds);
}
i++;
}
}
I also cranked up the fixedTimestep to 0.005 (200 ticks per second!)
with this value, i was able to get readouts for speeds up to about 8 M/s. The faster the ball is going, the less time it takes to decelerate to a stop, it seems. I maybe be wrong, but that doesn’t seem to quite gel with my intuition about physics,
at about 10 m/s it just goes from fullspeed to zero in a single frame, and i have to crank up the timestep some more to see anything in there