Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Angular velocity doesn't affect a bouncing ball.

Discussion in 'Physics' started by adrian-taylor09, Jan 25, 2021.

  1. adrian-taylor09

    adrian-taylor09

    Joined:
    Dec 22, 2016
    Posts:
    63
    I'm having a head-scratching physics issue that I hope someone can help me solve.

    I'm trying to replicate the effect that spin has on a bouncing ball. To test this out I have instantiated a rigidbody ball object, set it's max angular velocity, set its angular velocity and let it fall to the floor. What happens is that the spin only affects the bounce of the ball on the second bounce, but not the first... seems weird to me!

    If you watch the video below, you will see what I mean. Look at the rigid body angular velocity value in the inspector and you'll see that it is completely unchanged by the first bounce!



    Here's the code:
    Code (CSharp):
    1.  
    2.     RigidBody ball = Instantiate(ballPrefab);
    3.     ball.transform.position = dropLocation.position;
    4.     ball.maxAngularVelocity = 1000f;
    5.     ball.angularVelocity = (spinDirection * spinAmount);
    Using add torque gives the same results

    BUT, if I try making the ball kinematic, setting the angular velocity, then make it non-kinematic, it works as expected - giving me the spin effect on the first bounce!

    Anyone have a clue what is happening here?
     
  2. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    I can replicate your results by just dropping a sphere (I avoided Instantiating a prefab to keep things as simple as possible). There is a test scene attached for 2020.2.1f1.

    I found that the problem was related to size (but not inertia tensor) and the fixed timestep. Reducing the timestep in Edit - Project Settings - Time - Fixed Timestep to 0.01s restored normal behaviour, you will need to tune this value to your setup.

    Summary of tests (all with constant inertia tensor, no drag):
    Scale: 1.0, Fixed Timestep = 0.02s, OK
    Scale: 0.5, Fixed Timestep = 0.02s, Problem
    Scale: 1.0, Fixed Timestep = 0.02s, Sphere collider radius halved, Problem
    Scale: 0.5, Fixed Timestep = 0.01s, OK
    Scale: 1.0, Fixed Timestep = 0.01s, Sphere collider radius halved, OK

    I also tried reducing angular velocity to maintain tangential velocity at the contact point, but this made no difference.

    Sorry, I don't know enough about PhysX to say why this happens.

    Obviously, there is a computational overhead to reducing the fixed timestep.
     

    Attached Files:

    JeffDUnity3D and adrian-taylor09 like this.
  3. stevenwanhk

    stevenwanhk

    Joined:
    Jul 20, 2016
    Posts:
    113
    I experience the same issue. How did you change isKinematic? In the same frame?

    Using this does not work on my side
    Code (CSharp):
    1. body.isKinematic = true;
    2. body.isKinematic = false;
    3. body.velocity = velocity;
    4. body.angularVelocity = angularVelocity;
    and this
    Code (CSharp):
    1. body.isKinematic = true;
    2. body.velocity = velocity;
    3. body.angularVelocity = angularVelocity;
    4. body.isKinematic = false;
     
    Last edited: Apr 15, 2021