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.
  2. Dismiss Notice

Bug NaN's after setting Spring+Dampers to zero..

Discussion in 'Physics for ECS' started by MidnightCow, Oct 3, 2023.

  1. MidnightCow

    MidnightCow

    Joined:
    Jun 2, 2017
    Posts:
    30
    Setting the SpringFrequency and DampingRatio values of constraints to zero results in ExportPhysicsWorld writing NaN's to LocalTransform and PhysicsVelocity components..

    Here's the code i'm using ( in my case inside a parallel IJobEntity ):

    upload_2023-10-3_22-57-56.png

    You can see i'm working around the problem by setting to 0.001f

    I haven't tested this outside of my own setup to confirm whether this happens in just a basic joint setup or if it's specific to angular or linear constraints or what, but after hunting down where this bug was coming from in my code felt it was worth pointing out here..
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,428
    I'm not an user of ECS/Unity Physics, but as for what I can tell, setting spring or damper rates to zero is generally not a good idea physics-wise. Internal calculations typically use these values to figure out distances and velocities, and that involves dividing by the rates. If rates are zero then these calculations will output NaN, which will quickly propagate to the rest of the elements involved. Using very small values is a correct workaround.
     
  3. MidnightCow

    MidnightCow

    Joined:
    Jun 2, 2017
    Posts:
    30
    Hey, that makes sense but:
    - i don't think the api should be producing NaNs and it's really difficult to track where these are coming from when they do occur
    - setting to zero although logically from a physics engine perspective might seem like a bad idea, from an end-user perspective it's simply a way to make the joints have no strength without finding a workaround to disable or remove them completely ( which in ecs is a bit more of a hassle, they're not enableable either )
     
    Bob_work likes this.
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,428
    Yeah, maybe the API should check the range of the values and internally clamp to the minimum value the physics systems support.
     
  5. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    108
    So far, the joint system of DOTS is still very difficult to use, even a mess.