Search Unity

Performance of BoxColliders Sliding vs WheelColliders

Discussion in 'Physics' started by illumin8ed1, Jan 18, 2020.

  1. illumin8ed1

    illumin8ed1

    Joined:
    May 31, 2016
    Posts:
    5
    Hello all,

    I am building an infinite highway that has a lot of vehicles to simulate infinite heavy traffic. Its about 40 vehicles in a pool that are cycled from back-to-front or visa versa. In my initial prototype I just made the traffic vehicles simple rigidbody box colliders sliding across the highway's surface collider. This seems to be working well and smooth, but there are some issues such as some vehicles randomly getting stuck on the seams between highway pieces that you can't see visually, but the physics engine can. I've found some workarounds, like creating a step down, or a bridge, or making the vehicles hover, or rotate the vehicle front end up when it gets to the steams, or use a mesh collider and create a sled type front end, etc., but I am not entirely happy with any of those.

    I believe wheel colliders would solve the problem, and make some other parts of my code cleaner regarding steering and vehicle AI. But, I don't know exactly what goes on under the hood, so I was curious, would I get any performance gains or losses if I make the jump to wheel colliders? I guess I can spend some time and just test it myself, but I was wondering what the community would say?

    I am guessing adding 4 different wheel collision checks to 40 vehicles would increase time complexity, but does it simplify physics of sliding a box over a surface? What do you think?
     
  2. illumin8ed1

    illumin8ed1

    Joined:
    May 31, 2016
    Posts:
    5
    Anybody out there? Should I convert all these cars to use wheel colliders? Would I see performance gain or loss?
     
  3. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    I guess if the basic game mechanics stay like shown in the video, there is no need for dynamic rigid bodies for the cars, since they don’t really interact physically. You could make all of the just kinematic and get visually the same effect. How are you moving the cars at the moment?

    Unfortunately I don’t have information about the performance implications of wheel vs box colliders, but.. uh.. couldn’t you just change it and profile?
     
  4. illumin8ed1

    illumin8ed1

    Joined:
    May 31, 2016
    Posts:
    5
    The vehicles actually can interact physically, it is live traffic AI. They randomly change lanes. They have collision avoidance forward, and sideways if they are changing lanes, but depending on the situation they may crash and come into contact with each other. The vehicles are moved by rigidbody.AddForceAtPosition() and turned by rigidbody.transform.RotateAround() over their rear axles to get close to real vehicle movement as they loosely follow a path.

    Yes, I can just make the change and profile it. But I would have to drive them using their wheels, steer them by their wheels, mess with suspension and all, and its a huge change from what I have. I just wanted a theoretical opinion before spending the time on that.