Rigidbody. Acceleration of free falling object works bad
Jumped into Unity just a few days ago and trying to understand the basics.
I wanted to calculate movement's velocity of my objects and display it on the scene. When I had done it I noticed that acceleration of my objects was increasing not very well. I expected the changes of velocity during time like this way: 1.00, 1.25, 1.50, 1.75. 2.00. And in reality I got something like this: 1.00, 1.25. 1.50, 1.25, 1.75, 2.00.
I double-checked the math around Vector3.Magnitude and Time.DeltaTime properties but it works good. The issue is in position's changes of my object. Sometimes it doesn't increase sufficiently.
In this simplified code with free falling object my problem case still works:
Create new 3d project -> Add 3d Sphere GameObject -> Add rigidbody component -> Create script for Sphere object
public class SomeScript : MonoBehaviour
{
UnityEngine.Vector3 previousPositon;
float time = 0.25f;
void Start()
{
previousPositon = transform.position;
InvokeRepeating("Do", 0, time);
}
private void Do()
{
var magnitude = (transform.position - previousPositon).magnitude;
System.Diagnostics.Debug.Write($"magnitude: {magnitude}, velocity: {magnitude / time}");
previousPositon = transform.position;
}
}
And in few seconds I got:
magnitude: 20,36554, velocity: 81,46216
magnitude: 22,70029, velocity: 90,80115
magnitude: 21,54272, velocity: 86,1709
magnitude: 23,97562, velocity: 95,90247
magnitude: 22,71991, velocity: 90,87964
magnitude: 25,25085, velocity: 101,0034
magnitude: 23,89713, velocity: 95,5885
magnitude: 26,52618, velocity: 106,1047
Im stuck here. Thanks.