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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Making a car WITHOUT wheel colliders

Discussion in 'Physics' started by allencook200, Jun 22, 2021.

  1. allencook200


    Oct 2, 2020
    Hi, so I'm attempting to create a very simple rigidbody based car in unity, without the physx wheel colliders.

    What I have right now, is a box with a collider and rigidbody, with 4 cylinder colliders as wheels. I simply use addforce to propel the car and that seems to work fine. Next, I added some raycasts to the base of the two front wheels, so that it can detect if there's an object in front of them, which tells the game to add some force upwards to the front of the car, to try to help it climb over whatever the obstacle is in front of it (assuming it isn't too high.)

    Am I on the right track here?

    Another thing I wanted to ask is, how do I get the wheels to rotate correctly? I definitely don't need this car to be super realistic by any means, but I at least want the wheels to rotate proportionally to the car. Is there some sort of formula someone can give me, that will rotate the wheels based on how fast the car is moving?
    ashketchum455445 likes this.
  2. hippocoder


    Digital Ape Moderator

    Apr 11, 2010
    Using cylinders for wheels is not a good idea unless it's strictly visual because the contacts will be very hit and miss for the desired behaviour. It's best to use raycasts / sweeps and maths.
  3. allencook200


    Oct 2, 2020
    Unfortunately I don't know much math and I'm just looking for the easiest way to go about doing this. Do you have a barebones example using sweeps or raycasts?

    Edit: Okay so I followed a simple tutorial on youtube with how to do raycasts and it works pretty good, however if force is applied to the side of the car, the car will float freely to the side, but I only want it to move in the direction of the wheels (forward or backwards). Hopefully someone is able to assist me with this.

    Edit #2:

    I ended up using this script and it seemly works well with minor modifications, however if anyone has any other examples, please do post them, because there's hardly anything on the internet. It would not only benefit me, but other people in the future looking to work on their own custom vehicles.
    Last edited: Jun 22, 2021
  4. LeifStro


    Mar 23, 2015
    Using sphere colliders as wheels with zero friction works much better than mesh collider wheels. However, you still run into weird ghost collisions on uneven mesh terrain / roads etc. The best solution seams to be something like this simple raycast wheel, except switch it to sphere cast for a better approximation.
  5. arkano22


    Sep 20, 2012
    This video is a rather good introduction:
  6. johnsonrk


    Nov 19, 2023
  7. codebiscuits


    Jun 16, 2020
    (Mostly adding my context to the stuff said earlier, sorry johnsonrk)
    I talked over here a bit about how I'm using PrismaticJoint springs, zero-friction mesh-colliders & contact modification wheels:
    There's a great video here that demonstrates possible problems with raycasts:

    I'm not sure I feel like there's a "best" approach. I feel like raycasts would be awkward for the kind of vehicle/terrain behavior I'm trying to implement; but for other stuff I guess they're fine.
    Unless you're very maths&physicsy, or trying to learn because you want to, I'd definitely recommend letting an off-the-shelf solution do most of the work for you. I really like Edy's vehicle physics stuff, except that it's raycast-based (which is only a problem for my very specific requirements) (Edy's currently working on ditching the unity WheelCollider though, so I'm pretty excited:).
    I'm always delighted by this ultra-simple approach: