Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question WheelColliders are behaving strangely. How can I fix it?

Discussion in 'Physics' started by alexsecl, Mar 6, 2024.

  1. alexsecl

    alexsecl

    Joined:
    Jan 10, 2024
    Posts:
    15
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,558
    That might well be a visual effect, where the rotation rate matches the refresh rate. I recommend you to display the rpm of the wheelcolliders on the screen (or better, a graphic showing value vs. time) to verify if there are any actual issues.
     
  3. alexsecl

    alexsecl

    Joined:
    Jan 10, 2024
    Posts:
    15
    Added an RPM counter to each wheelcollider. The RPMs are also behaving horribly.

    https://drive.google.com/file/d/11SJrm_zvuqHBO8VOJDrCsWBraA3Pr56o/view?usp=sharing
     
  4. alexsecl

    alexsecl

    Joined:
    Jan 10, 2024
    Posts:
    15
    That's an interesting observation. I added Time Scale = 0.1 to the project to see what happens in slow motion.
    See for yourself on the video. With Time Scale = 0.1 everything is perfect. No stuttering.
    https://drive.google.com/file/d/1DSNJVfVMcRmlaW7rabObXJaHmRx3zzr6/view?usp=sharing

    Then I put Time Scale = 0.2. There was a slight stutter. You can see it in the RPMs of the colliders.
    But so far, it's not that critical.
    https://drive.google.com/file/d/1TugkucEpAJ6SDGpsrtiqpEChMdQSMnQY/view?usp=sharing

    Then I set Time Scale = 0.4. The stuttering is already clearly visible. And the collider RPM is starting to go crazy.
    It's clearly visible at 55 seconds into the video.
    https://drive.google.com/file/d/1h7g16vOe5Tkb8R2vcP352IAhGzM2y8Ly/view?usp=sharing

    What could it have to do with? The closer to time scale = 1, the worse wheelcoliders behave. It feels like Unity doesn't have time to process wheelcollider physics at time scale = 1. All project settings are default.
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,558
    Oh, that's surely that your code handling the WheelColliders is applied from the Update function. When dealing with physics, always use FixedUpdate for calling methods and modifying properties in the physics components or API.
     
  6. alexsecl

    alexsecl

    Joined:
    Jan 10, 2024
    Posts:
    15
    I forgot to clarify that I use PlayMaker for my project. Now I'm trying to figure out if PlayMaker uses the Update or Fixed Update function to write scripts.
     
  7. alexsecl

    alexsecl

    Joined:
    Jan 10, 2024
    Posts:
    15
    I checked the script that makes up PlayMaker. For all physical actions, it uses the Fixed Update function.
    I don't understand why this is happening with Wheel Collider...
     
  8. alexsecl

    alexsecl

    Joined:
    Jan 10, 2024
    Posts:
    15
    The problem with wheel colliders was solved.
    It turned out that it was affected by the mass of the wheel colliders. I have a heavy truck (mass 2500). And the colliders had a default mass of 10 kg. The radius of a wheel collider is 0.38, which means the wheel has a diameter of 0.76 meters. That's a big wheel, and it can't weigh 10 kilograms.
    I set the wheel collider mass to 40 kilograms and everything became perfect.
     
  9. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,558
    That's a good point! Don't be afraid of increasing the mass to 100 or 200 kg if necessary. This mass doesn't sum up to the actual vehicle's weight, but it's used in the internal calculations. The more mass, the wheel will change its rotation rate slower, which is convenient for numerical stability.
     
    alexsecl likes this.