I’m trying to simulate some projectile mechanics and the results are pretty good but I’d like to do better if possible. I have a sphere radius 1 and I add a Force in the y direction using Impulse mode; when I calculate the speed (magnitude) upon return to ground, it is not the same. It may be a problem in my code but if the rotation is frozen and positions are locked in x and z (drag and angular drag are disabled), it should be the same. For example, I ‘launch’ at 15 and it returns at 14.8 on the Debug.Log. I am using Update method, is that a possible issue or do I accept that there is some error in this?
Many thanks in advance for your comments.
in general the calculations are limited by 2 factors: floating point precision and the fact that you are in a discrete world. So there will be errors.
floating point precision will not be a huge factor when it comes to your example. that gets a bit more of a hassle when you move a projectile 1000000 units. There you will notice significant impacts.
the discretized world is more of an issue. Unity calculates all positions/rotations/velocities/accellerations new on every FixedUpdate. Which is every 0.02 seconds. This makes stuff look good enough but might result in some minor inaccuracies. Your 0.2 difference in speed probably result from one of these discrete steps and probably is connected to your choice of collision check method.(dicsrete, continuous, continuous dynamic … ) Perhaps another method will let your “projectile” move a bit further getting it to the full 15 speed again. You can also try to play with the physics settings to get higher accuracies - but beware of the performance cost that it comes with. For example you could lower the collision thresholds, raise the fixed update rate and raise the physics solver iteration count. If i remember correctly the documentation on this actually was fairly good.
Hope this answers some stuff, if there are more questions on this let me know.