Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug rigidbody physics error

Discussion in 'Editor & General Support' started by Astro-X, May 23, 2020.

  1. Astro-X


    May 16, 2020
    I was making a game that simulates spaceflight, that uses
    craft.AddForce(transform.forward * thrust, ForceMode.Acceleration)
    to exert thrust on the game object. I finds out that even if I set the drag to 0, the moving Game object still stops within seconds, and the speed of the game object tends to max out at some point while thrust is active, depend of the thrust and force mode. However, if I use UI to show the velocity
    Code (CSharp):
    1. public Rigidbody craft;
    2. public Text Speed;
    3.     void LateUpdate()
    4.     {
    5.         double velocity = Mathf.Sqrt((craft.velocity.x * craft.velocity.x) + (craft.velocity.y * craft.velocity.y) + (craft.velocity.z * craft.velocity.z));
    6.         Speed.text = velocity.ToString();
    7.     }
    and location of game object relative to the origin point
    Code (CSharp):
    2.     public Text XPos;
    3.     public Text YPos;
    4.     public Text ZPos;
    6.     void LateUpdate()
    7.     {
    8.         XPos.text = craft.position.x.ToString();
    9.         YPos.text = craft.position.y.ToString();
    10.         ZPos.text = craft.position.z.ToString();
    11.     }
    , the values of velocity shown by
    was perfectly as expected, when activate thrust, both the velocity value and the position changes at a constant rate (when the force mode is acceleration, the ratio between "velocity" and distance from origin is always around 5), when thrust is deactivated, the velocity UI would have no change, but the positions stopped changing. Since velocity is supposed to be the change of position in a certain time, this seems rather contradicting. And it doesn't matter if the positions were based on transform or rigidbody. The script of player movement was attached below.
    When I adjust the values of drag, things become a lot more interesting. when the "velocity" value is non-zero (not actual changing in position), and the drag is negative, the game object accelerates exponentially towards infinity, the acceleration offered by negative drag was dependent on the "velocity" value. However, if I were to set the drag to positive, the game object not only stops but start accelerating towards the origin, with the distance over time following an inversed logistic curve! the value of
    does decrease however, as my game object accelerates toward the origin at tremendous velocities.

    Attached Files: