- I have discovered some interesting behavior of relative speed between 2 game objects at a close distance (around 10m from each other). And move them as a group and test at different distance (0, 500, 1000, 1500m) from the world origin.
- It is highly likely a misunderstand, lack of C# knowledge, or lack of game engine knowledge from my side.
- The purpose of this new scene, name as Level 10, is try to understand why the relative speed increment steps increase as the game objects moved away from world origin. The goal is to calculate relative speed between 2 simple game objects as a group which is within 1000m from world origin with an accuracy of relative speed 0.001m/s.
- The following tests assume you set _rcsTranslationPower = 1; and press the keyboard button very fast when near world origin (within 100m). And set _rcsTranslationPower = 5 or 10; when you reach near 1000m from world origin.
- World origin XYZ direction all tested. All had problem. I notice that if the group is around 500-1000m from the world origin, the relative speed increment step is around ~0.003m. If the group is around 1000-1500m from the world origin, the relative speed increment step is around ~0.006m. If the group is within 50m from the world origin, the relative speed increment step can be around 0.0001m (Yes, 1mm/s), which is ideal for my simulator game.
- The whole scene had only 1 script, share with 2 game objects “CubeAsActiveSideSpacecraft” and “CapsuleAsPassiveSideSpacecraft”. Rigidbody component is also placed under these 2 game objects.
- The script ThrusterForSingleRbTesting.cs is placed under 2 game objects as mentioned above. To control the active side use F1 & F2. For passive side use F3 & F4.
This is one of the line I use to make the game object move in one direction.
_spacecraftTopParent_GamObj_Rb.AddRelativeForce(Vector3.down * _translationForwardAndBackward * _rcsTranslationPower * _spacecraftMassFactor * Time.deltaTime);
Below is how it calculate relative speed. The double variables here are for comparison only. It turns out double does not help.
IEnumerator IEnum_CalcRelativeTranslationAndRotationSpeed_ForTesting()
{
bool isPlaying = true;
while (isPlaying)
{
float prevDistanceTranslationOnAxisX_f = _distanceBetweenActiveAndPassiveSideForTesting_f;
double prevDistanceTranslationOnAxisX_d = _distanceBetweenActiveAndPassiveSideForTesting_d;
yield return new WaitForFixedUpdate();
float newDistanceTranslationOnAxisX_f = _distanceBetweenActiveAndPassiveSideForTesting_f;
double newDistanceTranslationOnAxisX_d = _distanceBetweenActiveAndPassiveSideForTesting_d;
_spacecraftRelativeSpeedForTranslationAxisX_ForTesting_f = -(newDistanceTranslationOnAxisX_f - prevDistanceTranslationOnAxisX_f) / Time.fixedDeltaTime;
_spacecraftRelativeSpeedForTranslationAxisX_ForTesting_d = -(newDistanceTranslationOnAxisX_d - prevDistanceTranslationOnAxisX_d) / Time.fixedDeltaTime;
}
}
- If you wish to test this, I have uploaded the scene to demonstrate.
RelativeSpeedAndWorldOrigin.unitypackage (5.3 KB)
Here is what you will see in the scene when you open the package.
Physic Settings
Time Settings