Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Subdividing physics timesteps for individual rigid bodies

Discussion in 'Physics' started by YaBoyShredderson, Jan 8, 2024.

  1. YaBoyShredderson


    Jul 5, 2023
    I have been working on custom vehicle physics for a while and have made a lot of progress. I have quite a realistic tyre model working, however i am having some stability issues.

    I have 4 separate wheel objects applying forces to a parent rigidbody, and it is generally stable, however not nearly stable enough. The lowest timestep i tested was 0.03125 (32hz) and i was surprised how stable it was, however it was only stable within typical realworld driving situations, so not close to what you want to do in game. Increasing the grip (even with a friction clamp that takes fixed delta time into account) or hitting certain bumps causes the car to jitter quite a lot.

    I am also getting a strange phantom force happening that wasnt present before when i tested 32hz, and this is present even at the default 50hz so something must have changed in my code to cause this as i have done quite a bit of work since then. This problem goes away at 100hz.

    I heard that forza horizon 5s wheels operate on a 360hz timestep, and im assuming that there entire physics simulation isnt running at that rate, just the wheels, so i want to try to do something similar, as many of the problems go away at higher frequency.

    Originally i thought of just putting my entire fixed update code into a for loop and calling physics.Simulate() at the end, but i dont think that would work. Basically i want to be able to loop over the code, say 4 times and have the previous loops force calculations actually applied to the rigid body so the smaller time step can be used to improbe accuracy, but only for the wheels.

    Any ideas on how i can do this? This is kind of a long post at this point but i feel its quite complex. My current idea is to do the calculations myself, such as looping through the code and using fixed delta time / loops as my timestep, and rather than applying the force, i calculate what would happen to the rigid body if the force was applied, and then use those results for the next loop, and applying the sum of these forces at the end. Thats a basic overview.

    There are some problems with this however. First problem, im not a physicist. I dont know how to do those calculations and even if i learn there is still the second problem.

    Problem 2 is that these forces are based on the results from a physics cast, which while i could do multiple times each fixed update, the results wouldnt change because while i would be calculating the rigid bodies velocity, angular velocity, position etc, none of that actually applies until the next frame.

    Any solutions? If i calculate the velocity, angular velocity, and position of the rigid body and then set them directly in each loop of the for loop, would that allow my physics cast to update its results correctly, even though the physics hasnt actually been updated?

    Sorry if this question is long and difficult to read, its a complex thing im looking to do and dont really know where to begin.