Search Unity

Add wheels to kinematic rigidbody

Discussion in 'Physics' started by sTorrr, Nov 16, 2019.

  1. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    89
    Hi. I have a moving kinematic rigidbody that is hoovering at a set distance above ground layer. I want to shoot out four rays directly down from vehicle above wheel position. I want wheel, without mass and collider, to be tracing the ground where raycast hits ground layer without applying forces back to the vehicle with kinematic rigidbody and custom movement script and gravity. What I am picturing is making wheel as child of an invisible object, without collider, that is allways connected to point where ray hits ground layer. This is to simulate a collison without adding collider to wheel.

    Is it possible to add this to a kinematic rigid body? Wheels will not apply torque or friction, They will just bounce up if vehicle hits a small bump, sort of like a perfect suspension that will absorb 100% of impact. There will allso be no mass on the wheels.
    Can I use wheelcolliders for this? Or will they allways add some force back to the kinematic rigidbody?

    Later I also want to add limits on how fast the wheel can moove along the ray. I will add spinning and turning of wheele to child object and will not impact turning or torque/friction that is controlled by vehicle controller script on kinematic rigid body. The wheel does not require a collider since it wont impact the vehicle physically. In other words there will be no springforces. Suspension will be manipulated by transforming/ yawing chassis, not collider, depending on speed, turnradius, braking, acceleration and so forth.

    I find great examples of suspension on realistic vehicles using gravity rigidbody, wheel colliders and raycast. But no examples of suspension and wheels for vehicles using kinematic rigid body with movement script.

    Thanks for feedback!
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,587
    I think that everything you describe should work the same in both kinematic and non-kinematic bodies. If you use WheelColliders they will react to the ground but the suspension and tire forces won't do anything to a kinematic rigidbody.
     
  3. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    89
    Hmm, interesting. I think when i tried wheelcolliders my vehicle would just shoot up in the air. I allso read somewhere that normal physics should not be mixed in with kinematic rigid bodies. How can the wheels reach the ground if there is nothing to push the vehicle towards the ground. Remember my vehicle is a hover vehicle flying at constant distance from ground. Not depending on raycasts from 4 corners, wheel. Its just one ray normal to ground layer unsing PID stabelizer to make it paralell to ground layer at any given time. How would you get the wheels to the ground? By adding mass to the wheel itself?
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,587
    That was when the rigidbody was not kinematic. Wheels will follow the terrain and try to push the car upwards, but if the Rigidbody is kinematic then it won't react to the forces coming from them.
     
  5. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    89
    Aha, so by adding wheels like a norma wheelcollider car, the wheels will seek towards the ground. Do I need normal physics rigidbody with colliders on the wheels? Its impossible to adde 0 friction and damping force to the wheelcollider. Wouldnt this to some degree interupt my vehicle and slow it down and make it bounce around? This is verry interesting by the way.

    I found a tutorial about raycasting and bulletholes in the walls. I was thinking about replacing the bullethole object with a wheel. But this will look strange and unnatural without more advanced scripting, floats and lerping I guess.

    Thanks alot for reply, I need to test this out!
     
  6. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    89
    Problem is that when adding the wheelcolliders to the vehicle im not able to remove all friction. I think the little mass and the little friction in the wheelcollider is preventing my vehicle from mooving forward. What is interesting is when im adding a sphere collider with teflon, no friction material, to my wheel mesh, with larger radius then the wheelcollider, so that the sphere is blocking the wheelcollider from reaching the ground, im able to move the vehicle forward and the wheels drop down to the ground, just a tiny bit above. This looks nice on a perfectly flat surface, but when entering a racetrack with curved track, the car will start to dig innto the ground and eventually go thoroug the layer. Guess its a bug, but not sure how to work around it