Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity 5 Vehicles - WheelColliders with hills

Discussion in 'Unity 5 Pre-order Beta' started by Venryx, Nov 20, 2014.

  1. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    I've been upgrading my project to work with the new Unity 5 WheelColliders, and I'm having some trouble. I can't seem to get a good combination of forwardFriction and motorTorque values that both is strong enough to bring the vehicle up a 30 degree incline, while also being stable/not jittering and sometimes making the unit tip over.

    Has anyone experimented with the Unity 5 WheelColliders and found a combination that works for this? To go up a 30-degree-or-so incline, while also not having jittering from setting the forwardFriction and motorTorque values too high?

    More details
    ==========

    GameObject heirarchy:

    Unit (Rigidbody, CustomCarController)
    >FrontLeftWheel (WheelCollider)
    >FrontRightWheel (WheelCollider)
    >BackLeftWheel (WheelCollider)
    >BackRightWheel (WheelCollider)

    Unit rigidbody setup:
    Code (CSharp):
    1. rigidbody.mass = 1500;
    WheelCollider setup (the base, anyway; I can get it going up hills by increasing forwardFriction stiffness, and having a high motorTorque value, but that causes jittering which has stability problems):
    Code (CSharp):
    1.  
    2. wheelCollider.mass = 1;
    3. wheelCollider.radius = .5f;
    4. wheelCollider.wheelDampingRate = .25f;
    5. wheelCollider.suspensionDistance = .1f;
    6.  
    7. wheelCollider.suspensionSpring = new JointSpring { spring = 0, damper = 0, targetPosition = 0 };
    8. wheelCollider.forwardFriction = new WheelFrictionCurve {extremumSlip = 1, extremumValue = 1, asymptoteSlip = 2, asymptoteValue = 1, stiffness = 1};
    9. wheelCollider.sidewaysFriction = new WheelFrictionCurve {extremumSlip = 1, extremumValue = 1, asymptoteSlip = 2, asymptoteValue = 1, stiffness = 1};
     
    Last edited: Nov 21, 2014
  2. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Well, I tried a lot of different things, including setting the WheelCollider mass to 400, enabling the suspension-spring with default values, using the default forward and sideways friction values, increasing and decreasing the wheel-damping rate, and changing how far from the car the wheel colliders were; the not-enough-strength<or>too-much-jittering dilemma remains, sadly.

    Could it be that the WheelCollider system doesn't like realistic values for vehicles? Is 1500 kg too high or too low for it to even support correctly?

    Anyway, my hope is to eventually study some other projects/demos that use the Unity 5 WheelColliders, with terrains that have moderately steep hills, to see how they handle it. In the mean-time, I'll probably go the route of making a simple wheel-collider script of my own, that just holds the car to the terrain, applies motorTorque through the use of a forward force, and steering through the use of time-based rotation (taking into account the movement speed, of course).
     
  3. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Actually new wheel collider needs realistic values to works properly. I don't know what jitter you getting, for me it works perfectly. Check you solver iteration count and fixed time step. With WCs attached to cars rigidbody you can set as much mass as you want.
    You have very little suspension travel, Im guessing that it causes your strange behaviour, because suspension is always fully compresed, yeah then it behaves somewhat strange.
     
  4. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    No worries, I made a custom WheelCollider script that actually works pretty well for my use-case. It has a much smaller feature set, such as lacking a curve-based friction model (it just has simple forward and sideways friction float-values), but at this point it does everything I need. It's also nice to have all the involved code open now (i.e. not relying on built-in components), so that if I need to change something within the wheel physics, I can do so directly.

    There probably aren't that many other projects where the script would be useful, but I figure I might as well post it in case anyone reading this has encountered the same jittering problem (and is fine with a much more basic solution). I created a Wiki page for it here: http://wiki.unity3d.com/index.php/VWheelCollider
     
  5. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Your kidding, right?
     
  6. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Nope. My game doesn't have a first-person controller for the car (you're just watching lots of units from above), so it doesn't matter much if the units don't have realistic friction or acceleration. (I just need something to get them moving from place to place stably, while also using the physics engine so it can interact with forces and impact-collisions and such)
     
  7. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    Have you implemented the vehicle as described in the update notes? It's slow and jitters like crazy on the flat plane. This is with Unity 5.0.0b15. IIf you've got a working example of a vehicle, I'd love to see it.

    edit: Oh yeah, there also seems to be zero rolling friction.

    Neat script, it gives me a ton of ideas but any idea how to get this to turn while moving but not under acceleration? It doesn't turn at all without pressing the gas too, which isn't very realistic.
     
    Last edited: Dec 5, 2014
  8. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Unfortunately I don't have working example, as I was just playing with new collider to see what behaviour I can get with it, and I was pretty happy with it. But as I said it was just playing around and didn't even save the scene. It was in little older version, though.
     
  9. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Sorry, not really. My game has a limited use for it (AI vehicles), so I didn't have the need to make it work convincingly for human users. (or AI uses where the flaws would be more obvious)

    You could try this other wheel-collider replacement on the wiki: http://wiki.unity3d.com/index.php/WheelColliderSource

    It's apparently intended to be a replacement for the built-in one that's as-close-to-the-original as possible.

    However, it might be helpful to note that I tried that myself beforehand, and after hours of experimenting, couldn't get it to work. If you have more patience than I do, and a hunch that it would in fact still work with Unity 5 after some tweaks, it might be worth the effort though. If so, the page would greatly benefit from a working example package/scene!
     
  10. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    Yeah, I found that one while looking for alternatives after I posted. I did get a working scene just following the directions on the CarController.cs page but the suspension needs a lot of work. It has a bad feedback issue when the car isn't moving. Didn't have much luck disabling the suspension either but I haven't had a lot of time to put into it.
     
  11. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Odd. I must have been doing something fundamentally wrong (I also followed those instructions, but failed to get any main/forward movement--I investigated it further using debugging and such, but I forgot what results I got/what the problem was narrowed down to).

    Anyhow, glad to hear you got it working (for the main portion, anyway--of friction, thrust, and turning; I don't know much about it, but I imagine the suspension is one of the easier components to fiddle with and fix).
     
  12. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    I can throw a project up somewhere if you'd like to explore it further.

    edit: Actually, I'll just attach the file to this post. Here ya go. Looks like it works differently in Unity 5 vs. Unity 4.6. In Unity 5, it has the extreme suspension jitter without tweaks. In Unity 4.6 it doesn't have the jitter but it's easier to roll the car than in Unity 5 and it doesn't deal well with a roll.

    Attached is the Unity 4.6 project.
     

    Attached Files:

    Last edited: Dec 7, 2014
  13. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Thanks! I'll definitely take a look at that at some point.