Search Unity

Why set Rigidbody velocity is inaccurate

Discussion in 'Physics' started by Drcw, May 18, 2020.

  1. Drcw

    Drcw

    Joined:
    May 8, 2020
    Posts:
    1
    Hi,
    I am testing a billiard game and this is a problem I encountered.
    222.png
    As shown in the picture, a small ball with a rigid body component added is placed on the table, and the cushion has the 'cushion' tag on the side.

    This is the script of the ball.
    Code (CSharp):
    1.      private Rigidbody rb;
    2. void Start()
    3. {
    4.      rb = GetComponent<Rigidbody>();
    5.      rb.velocity  = new Vector3(0,0,1);
    6. }
    7. void Update()
    8. {
    9.      print(rb.velocity);
    10. }
    11. private void OnCollisionEnter(Collision other)
    12. {
    13.      if (other.gameObject.CompareTag("cushion"))
    14.      {
    15.          rb.velocity *= -1;
    16.      }
    17. }
    I think the ball will get a speed of (0,0,1) and become (0,0,-1) after collision with the cushion, But after running the console shows, the ball speed becomes (0,0,0.2), And becomes (0,0,-0.1) after the collision, what happened?

    I tried setting Physics Materials to the ball and the borders, the friction of the material is set to 0, bounciness is set to 1, and bounce combine is set to maximum, but the information output by the console is the same as before.

    Ball Rigidbody properties: Mass: 1 Drag: 0 Angular Drag: 0

    Thanks in advance!!!