Search Unity

Wheel Controller 3D - Customizable Three Dimensional Alternative to WheelCollider

Discussion in 'Assets and Asset Store' started by NWHCoding, Nov 17, 2016.

  1. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Hey MHW. Thanks for the reply. I don't particularity want to set a realistic curve, if I am honest. I want to set the rear tyres to be linear and experiment from there. Is there a packejka visualiser I can use to quickly visualise the curves I make?
     
  2. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Unfortunately, no.
    You could start with the Arcade preset then - it is quite close to linear. Only the first two parameters are important (one defines the slope and other the strength of the peak, can not remember which is which tho).
     
    IceBeamGames likes this.
  3. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Ok, thank you.
     
  4. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hi,

    Could you please explain how to properly implement this? I am trying to use this for a tracked vehicle.
    Code (CSharp):
    1.  
    2. WheelController.trackedVehicle
    3. WheelController.trackedOffset
    4.  
    Do I place a separate "virtual" wheel in the middle of the track, in addition to the road wheels? Or do take the radius of the virtual wheel (of the track) and spread it among all the wheels?

    Thanks!
     
    Last edited: May 16, 2019
  5. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    both of those are intended just for internal use with NWH Vehicle Physics (which include WC3D as a wheel solution). WC3D does not support (out of the box) tracked vehicles nor does it mention them anywhere on the asset page.
    What trackedVehicle flag mostly does is disable any wheel slip (tank can not slip the wheels inside the tracks). There are some other minor changes.

    But in short you could simply apply positive torque to wheels on one side, and negative torque to wheels on the other side and you would get the tracked vehicle - minus the tracks (a bit oversimplified but it will work with correct slip settings). This is basically how tracked vehicles work in NWH Vehicle Physics:
     
    krou and FlightOfOne like this.
  6. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Thanks for the response, what you mentioned is what I am already doing and it is working really well. Just needed some clarification to above mentioned properties -thought maybe there's a better way to do this.

    Any near future plans for an asset that would handle just the tank tracks and wheels? I know you have a complete solution package but I don't really need the full package (engines etc..).

    P.S. Since you mentioned asset store, it actually does indicate Tanks. In fact, line below was the primary trigger for me to purchase this.

    "• Suitable for different kinds of vehicles: cars, trucks, motorcycles, tanks, etc."

    Since almost all tanks are tracked, I assumed above properties were in place to accommodate those. But no worries, I am a very satisfied customer.
     
    Last edited: May 17, 2019
  7. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Ah, that is because there was a tank in the demo in the early versions, just without the tracks. Forgot about that.
    If you send me an email w
    Ah, my bad then. The description was written about two years ago and I forgot about that one. There was a tank for a short time in the demo scene but it was trackless, and the options that you see came much later. The intention was to let customer know it can be used on a tank - but not that it has tracks built-in. Hopefully this has not confused anyone and if it has I will remove it.
     
  8. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Not a problem, I bought this long time ago. I never expected it to be a fully tracked solution, but thought it can be extended to a tracked solution, which it has and works well for me. When I saw those property (especially the virtual radius), I thought to myself NWHCoding knows his stuff and is a genius, thought of everything! :) I got excited and I just wanted to see if there was a proper way to implement it, wasn't questioning the asset, just needed guidance. I thought instead of using 5 wheel per side, I can use 1 wheel (in terms of physics calculations, 10 wheels vs 2 is much less taxing) with a large radius using that radius offset property.
     
  9. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Hey again NWH.

    I was wondering if I can easily adjust the length the springs extend to while keep the same rest point? I am making a rather arcady racer and want to be able to keep the wheels on the ground while bouncing around quite a lot.

    Also, is it possible to adjust how far the renderable wheels extend to separately from the actual simulated wheels? Might be useful so that they don't look so ridiculous when going over large jumps...
     
  10. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668

    Attached Files:

    Last edited: Jun 1, 2019
    krou likes this.
  11. nimu7410

    nimu7410

    Joined:
    May 15, 2019
    Posts:
    1
    Hey please can anyone tell me when I'm trying to add the wheel controller script in the wheels of a vehicle, wheel collider itself comes to center of the vehicle and also I'm unable to move that wheel collider.
    Please help me I'm in serious pain.
     
  12. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    105
    @NWHCoding Hello! I think I may have found a bug and would like to get your opinion.

    I have a vehicle that's working and performing great! I noticed when I pause and then unpause my game, my vehicles wheels will now jitter around endlessly. I'm pausing the game by setting the 'timescale' to '0', and then un-pause by setting the 'timescale' back to '1'. I was able to repro this issue in the Wheel Controller Demo scene. It's very subtle... but it occurs. A higher coefficient value (like Slip=2 and Force=4) better exposes the jitters. Again, these higher values work perfectly fine, up until the game is paused/un-paused... then the jitters occur.

    Is this a legit bug or should I not be pausing the game in this fashion? I'm using playmaker to set the timescales.
    Thanks for any feedback!
     
    Last edited: Jul 3, 2019
  13. Smrdis

    Smrdis

    Joined:
    Sep 19, 2016
    Posts:
    7
    Hi.

    Is it possible to use mesh collider as road? I just copypasted car from demo to my scene and car physics looks really bad. Car jumps and flies away on any bumps.
     
    Last edited: Jul 12, 2019
  14. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    It certainly is. Just disable Queries Hit Backfaces in Physics settings (Project Settings > Physics) and you should be good to go. The jumps are there because raycasting an infinitely thin mesh (i.e. a plane) can sometimes result in a flipped normal if this option is enabled.
     
  15. Smrdis

    Smrdis

    Joined:
    Sep 19, 2016
    Posts:
    7
    Thanks for answer. Queries Hit Backfaces was disabled in my project by default, so it can't help. But I have tried to disable Queries Hit Triggers and currently it works well %).
     
  16. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Hey @NWHCoding.

    Is there a function to reset all wheel forces, for instance because you are resetting the vehicle position because it fell off the track?
     
  17. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    There is not yet. I am currently working on 2.0 update for NVP (which uses WC3D for wheels) and am implementing Reset() function in all of it's classes so WC3D will get one too. At the moment you can set wheelController.wheel.angularVelocity and wheelController.wheel.residualAngularVelocity to 0 and it should effectively reset it. ResidualAngularVelocity is the only value carried over from the last frame, the rest is calculated on per-frame basis (assuming I did not forget something).
     
    FlightOfOne and IceBeamGames like this.
  18. VagabondOfHell

    VagabondOfHell

    Joined:
    Sep 17, 2013
    Posts:
    15
    Hi @NWHCoding

    I'm looking at some asset store utilities for wheels and came across yours. I'm looking to make some modular vehicles similar to


    Would WC3D work well in that situation (where the wheels are attached to the vehicle with fixed joints for runtime building)? And are there any restrictions with how the WC3D wheels are placed (i.e. placing them upside down on the 'roof' of the vehicle for when the vehicle flips for example)?

    Thank you!
     
  19. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    There are two things to take into consideration when placing WC3D wheels:
    • They have to have a spring. Spring is a part of the wheel and setting spring length to 0 is not recommended since then you will get an effect more akin to a collision (impulse response) rather than smooth rolling over bumps.
    • Wheels only detect on the lower half, and only on the tire thread portion (bottom 180 degrees). This is usually not a problem since a collider can be placed to cover the top part of the wheel but in some cases you might want the wheel to work from all sides and this is not it.
    They can be placed in any position, rotation or orientation.
     
  20. Odiobill

    Odiobill

    Joined:
    Jul 16, 2018
    Posts:
    10
    Hi NWH,

    I'm working on a project where I need to attach small wheels to objects than can be rotated in any position as they, de per se, can be attached to other objects in a chain.
    Think of those wheels like the casters in a typical office chair. The Unity wheelcollider is giving me a lot of headaches because of the above-mentioned rotation. Do you think that WC3D can be a suitable solution for my needs?
     
  21. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    there are two limitations:
    - The wheels are intended to be used with spring length of larger than 0.
    -The hit detection only works on the bottom half of the wheel and not on the sides.
    If you are fine with those two you should be fine. Also, if it does not work for you just request a refund by sending me an email.
     
  22. Odiobill

    Odiobill

    Joined:
    Jul 16, 2018
    Posts:
    10
    Thanks for your reply, NWHCoding. I still need to experiment with your asset but I think it's great anyway, and for what I saw, it looks extremely polished. If it's not suitable for my current project, it will probably be handy to have anyway for something else in the future :)
     
  23. Susihiisi

    Susihiisi

    Joined:
    Jan 11, 2018
    Posts:
    32
    Does this work with custom gravity? Unity's default WheelCollider seems to be dependent on project's gravity settings and it won't get any friction on spherical planet.

    Edit: Also how about NWH Vehicle Physics? Is there anything that is relying on default gravity or a specific plane?

    Edit2: I went ahead and bought NWH Vehicle Physics. Seems to work well on a spherical planet.
     
    Last edited: Sep 30, 2019
  24. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    Hey @NWHCoding,

    I have a new problem with the wheel controller plug in. Because my vehicles are driving over roads which are suspended in the air, like a roller coaster, sometimes the wheel can fall off the edge of the track, but the vehicle doesn't fall off, so the wheel essentially gets trapped under the road, because the suspension is fully extended.

    What would be the easiest way to adapt your code to deal with this situation?
     
  25. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The easiest solution is to make sure that you have a collider of some kind covering the top part of the wheel. You can use the auto-generated rim collider, or if that is not enough a box collider that has about the same dimensions as the wheel if the wheel can extend very far and rim collider is not adequate.
     
  26. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    I don't think its because they need a rim collider. The entire wheel has fallen so low, because of the fully extended suspension and got stuck under the road, while the vehicle is on top. Its only really because its very arcade handling with huge sprint lengths that wouldn't happen in a more realistic game. Like this:

    Wheels_Under_The_Ground.jpg
     
  27. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Oh wow, that really is some extreme spring travel. But one thing strikes me as very odd - rim colliders are way smaller than the wheels. Are you sure you do not have scaling on the model.
    Also, I notice that your springs extend way over the hood of the car - might I ask what benefit is there to having wheels go so high? I hope you do know that you can move the pivot point of the spring simply by moving the WheelController's transform.
     
  28. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    170
    The wheel are smaller because I created the physics wheel and tweaked the handling before I bought the car model. I have adapted your code so the render wheels can remain in their place and the simulated wheels still move them about because it remembers the new offset and applied that after. The reason the springs are so long is to deal with the huge jumps the game has in them. Think jumps from Trackmania. Huge.

    Anyway, any idea how to detect the wheel being under a collider while the body is on top?
     
  29. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    hi, have some questions:
    - performance difference with Unity's built-in WheelCollder ?
    - scalabilty? image town with car's traffic, for example 30 active cars using wheels.
    - mobile performance wise ? with traffic 30 cars.
     
  30. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    there are two modes: multi-ray and single ray. Multi ray is recommended for player vehicle and the performance depends entirely on the settings. The rays are batched so they are quite fast. Expect a 4 wheel vehicle with fairly high scan resolution to take about 0.20ms per frame, while in single ray mode that will be under 0.05ms (both measured in editor, a out half that in build). Trouble comparing with the default wheelcollider is that wheelcollider is native code and can not be profiled so I can not answer that unfortunately.
     
  31. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    So can one simulate a stand-alone wheel? Like a wheel that's come off a car. When I create a simple wheel and wire up the Wheel Controller (default settings, except parts that need to change like raycast ignore and wheel visual), its behavior doesn't make sense. If I start it in the air and drop it, when it hits the ground it flies off at a right angle. One would expect it to bounce up and down and maybe roll. Certainly on a ramp you'd expect it to roll away, but not fly off to the side.
     
  32. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Could you please send me more details on how to reproduce this to the email, or even better a scene?

    The only way to simulate detaching (i.e. a wheel that fell off) would be to completely disable WheelController and add a cylindrical collider to it so that it acts as an independent physics object.
     
  33. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    But, as I'm sure you know, there is no cylindrical collider in PhysX. And a sphere certainly doesn't look right. :)
     
  34. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    True, but there is code in the WheelController3D itself that makes a mesh cylindrical asset. Just change the values for start and end angles to be 360 degrees apart. The code is under "GenerateRimCollider" or similarily named function.

    Or if you want to take the easy road just add Convex mesh collider to the wheel visual and it will get auto-generated.
     
  35. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    Yeah, I went the direction of a mesh collider set to convex and just used physics to do the work. In my case the "loose" wheel is actually powered, so having some good traction/slip physics would be nice, but probably not worth the effort.
     
  36. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    WheelController 4.0 is coming out in a few days time. This is more or less the same WheelController that will be used in the upcoming NWH Vehicle Physics 2 with some major improvements:
    • No creeping on slopes.
    • Better friction calculation.
    • Performance improvement of at least 30%.
    • New custom editor.
    • Friction settings are now solved inside FrictionPreset scriptable objects and allow for adjusting of curve parameters with realtime preview.
    • Many more general code improvements, etc.
    New editor:
    upload_2020-2-7_14-4-52.png
    upload_2020-2-7_14-5-15.png

    No creep demonstration:
     
    Last edited: Feb 11, 2020
    hodge47 likes this.
  37. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Wheel Controller 4.0 is out with many changes (check the post above).
    Due to the amount of changes your project will most likely require some re-configuring but
    it should be worth it. If you find any bugs in the new version send me an email to nwhcoding@gmail.com so I can fix them as soon as possible.
     
    hodge47 and Guacamolay like this.
  38. Guacamolay

    Guacamolay

    Joined:
    Jun 24, 2013
    Posts:
    63
    I'm going to wait until the Vehicle Physics update is also released before diving into this, but I'm really looking forward to it and wanted to say thanks for all the work on this asset - you've saved me a lot of time and headaches, and made something that's really rock solid and also fun to play around with!
     
  39. ElanGr

    ElanGr

    Joined:
    Mar 10, 2019
    Posts:
    4
    Can these wheel colliders detect collisions using unity’s OnCollisionEnter and OnCollisionStay methods?
     
  40. emfinger

    emfinger

    Joined:
    Aug 23, 2017
    Posts:
    9
    Hi NWHCoding - question for you related to side-slip and collision detection. I'm noticing that when my wheels start slipping sideways the collision detection fails and they drop into the ground a little. At this point they end up continuously generating energy so the vehicle continually accelerates, tied to the ground. I've attached a few screenshots to show before and after shots. as well as some configuration parameters for your wheelcollider script. I've tested a lot of tuning of the friction values / forces etc. and it always happens.

    Before bug (https://imgur.com/ontkJj2):


    After bug starts (at which point speed never drops to zero even if left alone for 10+ minutes - at which point speed is > 100 mps) (https://imgur.com/55clTcQ):


    Imgur album: https://imgur.com/a/I6hka0c


    As a minor update - is it expected that the script doesn't allow 0 force / 0 length suspension / springs? For our case we'd like to set them to 0 to handle the simulation elsewhere.
     
    Last edited: Mar 24, 2020
  41. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    the issue could be in the new creep fix for the low speed friction. I have tested it a lot but it could be that there is an issue in some edge case.

    You are correct, spring length shorter than Time.fixedDeltaTime * 10 (or thereabouts) is not recommended. This is because the force is calculated based on the length of the spring and if there is not spring no force can be generated. There is a fallback for the case when a spring bottoms out but it is not intended to be used as suspension.
     
  42. emfinger

    emfinger

    Joined:
    Aug 23, 2017
    Posts:
    9
    Thanks - I actually found out that it was a collision with my collider that was causing that issue - i had set them to the scan ignore layers, but they still collided - shrinking the size of the colider prevented the issue - though I still have some trouble tuning the friction parameters to allow the wheels to not slip all over the place but still be able to turn as casters - but that's a problem for me to figure out :)

    Regarding the spring length - is there any planned support for 0-length / non-existent springs in the future? I know the built-in wheelcolliders support 0-length springs, and given the scale of these objects, I'm having to set spring constants on the order of 1000 and a length of 0.01 to keep the model from falling through the floor but it's still a little jittery.
     
  43. MMT

    MMT

    Joined:
    Apr 12, 2013
    Posts:
    20
    Hello, after updating wheel controller from 3.x to latest if got really weird drifting. From the video you can see. Also car is turning differently to left and right, I can see that from debug values also. I just cant find anything wrong from my setup. Everything is centered and all 4 wheelcontrollers have same setup. Downgrade to older version -> no problem. Any help?
     
  44. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    This is a bug that was introduced in 4.0 with PID controller being used for when speed is ~0. Unfortunately in some cases it turns out it can cause the drift.

    Luckily it is easy to fix - switch inspector to Debug mode and go to WheelController, forward friction foldout and set Kp = 1, Ki = 0, Kd = 0. I will push an update tomorrow.
     
  45. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hello,

    I'm looking for a solution to make vehicles using Wheel controller follow a path or a target. Could you recommend something compatible if there is anything out there?

    thank you so much
     
  46. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    Any asset that works with WheelCollider will work with WheelController3D too. Just note that if you need a wheel to follow a rail, as in train game then I can not recommend the asset for that any more than I can recommend the default WheelCollider.
     
  47. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi,

    thanks for the information. I’m wondering how to move in a turn based game a vehicle with physics wheel to follow a navmesh path. No trains :)

    would you recommend something you know?

    thanks again
     
  48. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Unfortunately no since I have not worked with any related assets.
     
  49. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    A major update (v4.1) is coming out as soon as it gets approved.
    This will bring all the work that was introduced in NWH Vehicle Physics 2 to the asset:
    • Accurate friction calculation with correct friction circle. This solves the issues with vehicles not drifting when there is wheel spin.
    • Removed derivative component of PID controller for low speed calculations. This could cause vehicle drift after the vehicle has been sitting for prolonged time.
    • Reworked application of forces to the Rigidbody. More stable suspension.
    • Wheels now apply torque to the vehicle. E.g. spinning up the wheel in mid-air will tilt the vehicle backwards.
    • Performance improvement on some devices.
    • NUI update to make editor look the same on 2018.x and 2019.x.
    • Bug fixes.
    Demos for 4.1 are still not up but you can try them out in the NWH Vehicle Physics 2 demo which uses WheelController v4.1.
     
  50. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Ok. Thanks anyway!
    Best regards