Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Wheel collider help

Discussion in 'Editor & General Support' started by sport20, Mar 6, 2010.

  1. sport20

    sport20

    Joined:
    Jun 14, 2009
    Posts:
    39
    Hello,

    I am trying to create a racing game but I have a hard time understanding the fundamentals of using the wheel collider. Can anyone help me out with a step by step procedure about how I should get started with this?
     
  2. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
  3. sport20

    sport20

    Joined:
    Jun 14, 2009
    Posts:
    39
    Thanks! I've actuallt tried both of them already. Someone told me that they tried jcar as well but that I shouldn't use it since it's jacked up.
    I guess I'll just have to go back through them again and see how much I can get out of them since those are the only two that seems to be around.
    Thanks again though.
     
  4. sport20

    sport20

    Joined:
    Jun 14, 2009
    Posts:
    39
    Ok so I have the example project with all the scripts and everything.

    I have tried my own little project where I created a simple car. I used the cube for the car body together with 4 cylinders for the wheels.

    I have created 4 wheel colliders separately from the wheels by creating empty game objects and applied wheels colliders to them.

    I have applied the player car script from the example project to my simple car. It doesn't work. I know I am doing something wrong that's why it's not working. Can anyone shed some light on this subject for me?
     
  5. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    I've attached a project with a very simple demo of a car made with wheel colliders. The key thing to note about these is that they don't really have a physical volume like most other colliders. They are actually implemented by measuring the distance to the ground and applying an upward force to simulate what the wheels would be doing (a bit like a carefully controlled rocket thruster in the position of the wheel).

    You shouldn't rotate the colliders around the wheel axle to make the graphic rotate because this results in the "thruster" getting pointed in the wrong direction. However, you can steer by turning the collider object left and right around the Y axis. The calculation to convert the collider's RPM value into a rotation angle is straightforward and is noted in the code.

    The centre of mass on the rigidbody often needs to be lowered slightly to make the car stable while turning. There are also many other nuances you can add to give better handling or otherwise make the car more suitable for your gameplay.
     

    Attached Files:

  6. souperdave

    souperdave

    Joined:
    Jan 7, 2011
    Posts:
    7
    Three Cheers for andeeee!! WhaHoo! <soup passes andeeee a Pint!>

    Thanks a handful mate, your concise response and helpful code is exactly what I was looking for!! I'm relatively new to the site but you seem to pop up all the time - in the right places, for me anyways. I hope you're getting rewarded for your efforts! I may start a fan club for you :)

    souperdave

    for others searching for clear answers via the search engine:

    easy concise clear wheel collider wheelcollider
     
  7. geektothepowerofgeek

    geektothepowerofgeek

    Joined:
    Jan 25, 2011
    Posts:
    3
    thats excellent,
    but is there any chance you could alter the script to include suspension on a wheel, that is to say, the moving of the graphic wheel.
    thanks
    rob