Search Unity

NWH Vehicle Physics 2

Discussion in 'Assets and Asset Store' started by NWHCoding, Apr 8, 2020.

  1. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    Vehicle creation is not working for me. Two different cars with the same problems.

    1) Some sort of sphere collider is making the car roll around like a basketball
    2) Wheels do not work

     
  2. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    This is most definitely an issue with the model pivots and/or rotation. I made a small guide on that here: Checking Rotation [NWH Vehicle Physics 2 Documentation]
    A lot of models downloaded from around the internet are not Unity-ready and might have issues such as:
    - Unity convention is that Z-axis points forward, X-axis towards the right and Y-axis up. This is usually not the case with the models exported from the 3D modelling software if not explicitly exported / designed for Unity.
    - Pivots of the objects (the point that gets returned by transform.position) can sometimes be at the origin. This means that if you ask all 4 wheels where the transform.position is you will get (0,0,0) for all 4.
    Both issues are easily solved in 3D modelling software such as Blender. That said, it can be done without 3D modelling software but is a bit more fiddly - Unity has even made an official guide on this: Unity - Manual: How do I fix the rotation of an imported model? (unity3d.com)

    So if you are getting models from a 3rd party it is always best to verify with the author of the model that it is ready for Unity - most of the models on the Asset Store are. If you know how to use Blender this is no more than a few minutes of work but for a novice the learning curve can be quite steep.

    Hopefully this helps.
     
    ZGoodwin likes this.
  3. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    @NWHCoding This helps me out greatly. Yes, the source of the model always has messed up model pivots. I'll give the unity rotation fix a go before attempting blender. Thank you for the excellent answer.
     
  4. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    134
    Mirror networking, why other clients wheels are not rotating? (Pun is working as expected).

    Also, this error is thrown, what could be the reason for it?

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <9577ac7a62ef43179789031239ba8798>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <9577ac7a62ef43179789031239ba8798>:0)
    System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <9577ac7a62ef43179789031239ba8798>:0)
    Mirror.SyncList`1[T].set_Item (System.Int32 i, T value) (at Assets/Mirror/Runtime/SyncList.cs:378)
    NWH.VehiclePhysics2.Multiplayer.MirrorMultiplayerVehicle.Update () (at Assets/NWH/Vehicle Physics 2/Scripts/Multiplayer/Mirror/MirrorMultiplayerVehicle.cs:84)
     
  5. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    This would indicate the number of sound components on the vehicle changed between array initialization and the network sync. I am right now working on v1.5.1 so will investigate this issue. The wheels not turning are almost certainly related to this as Unity will stop script execution after an error happens. If you want to proceed with the deveopment for the next few days until the fix is released you can comment out the 'for' blocks at lines 56-61 and lines 81-87.
     
  6. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    134
    Just for info, Lada Niva from Mirror Demo doesn't trigger this error but wheels still don't rotate.
    I'm using Monster Truck from the Playground demo (made a prefab out of it) and I've deactivated some modules related to effects and similar to improve performance, but nothing related to sound. When I use this vehicle errors show up.
    I'm just exploring things, it is not urgent.
     
  7. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    Thank you for the report. Will certainly be investigating this
     
  8. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    NWH Vehicle Physics 2 is 40% off at the moment as a part of Unity Asset Store New Year Sale.
     
  9. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    Version 1.5.1 is on the way with the following changes:
    • Add Rigidbody interpolation by default with an option under Settings tab to choose a different value.
    • Fix InputProvider instances list entries duplicating with each scene reload.
    • Added InvertClutch, InvertBrakes, InvertThrottle, etc. options to VehicleInputHandler.
    • Improved input documentation.
    • Improvements and bug fixes related to brakes.
    • Fix deadzone.
    • Updated Mirror and Photon scripts for compatibility with newest versions of each asset.
    • Fix NUIDrawer causing Unity Editor to enter infinite loop due to a bug with UnityEditor.ReorderableList elementHeightCallback when 0 is returned.
    • Fixed turning off low beam lights while braking resets brake lights.
    • Added “Require Camera Rotation Modifier” and “Require Camera Panning Modifier” options to SceneInputProviders, mainly for use with touch screens where modifiers are not needed. Enabling these options makes cameras able to rotate/pan without pressing additional buttons.
     
  10. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    231
    Any plans to support Rewired?
     
  11. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    I opted for InputSystem support but the InputProvider system that NWH Vehicle Physics 2 uses allows for easy integration of 3rd party input systems. All that is needed is to inherit from VehicleInputProviderBase and implement the return functions, such as:

    Code (CSharp):
    1. public override float Throttle()
    2. {
    3.     return {insert Rewired code here};
    4. }
    More about InputProviders here: http://nwhvehiclephysics.com/doku.php/Setup/Input
     
  12. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    A new update with major changes for VehicleSetupWizard is on the way. The wizard will now feature a "Preset" field where a VehicleSetupWizardPreset can be assigned:

    upload_2020-12-21_16-36-15.png

    VehicleSetupWizardPreset is a simple ScriptableObject that gives the wizard guidelines on how to set up the vehicle. Additional step has been added to the wizard that runs after the basic setup (current) and it configures the vehicle based on the parameters in the preset. The update will ship with presets for most vehicle categories.
    The result of all this is that the wizard will produce a vehicle that is much closer to the required result - this includes pre-configured powertrain, suspension, physical properties and other settings.

    Updated VehicleSetupWizard, note the preset field at the top. Leaving the field empty will give you the same results as the current wizard:
    upload_2020-12-21_16-40-20.png

    The preset system is currently in beta so if anyone wants to try it out before the update appears in the store send me a message.
     
  13. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    Semi truck by GR3D from NVP1 is coming back in v1.5.2. Expect the update to land before Christmas.
    upload_2020-12-22_19-43-58.png
     
    dsilverthorn and Rotary-Heart like this.
  14. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    v1.5.2 is on the way with the following changes:
    • Added presets to VehicleSetupWizard. Vehicles are now automatically configured based on the preset settings and vehicle properties. E.g. heavier vehicles will have suspension and friction adjusted to match the weight.
    • Added semi truck to the demo scene. Model provided by GR3D.
    • Fixed trailers braking on reverse.
    • Minor bug fixes and improvements.
     
    Mixa1985, Freznosis and dsilverthorn like this.
  15. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    294
    Last edited: Dec 28, 2020
  16. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    Update 1.5.3 is on the way with the following changes:
    • Fixed NRigidbody throwing an error when Rigidbody rotation constraints are used.
    • Fixed build failing due to editor code.
     
  17. chaoyang1015

    chaoyang1015

    Joined:
    Nov 22, 2016
    Posts:
    6
    How to use semi-linkage, I want to keep the vehicle moving without stepping on the accelerator or on the clutch
     
  18. chaoyang1015

    chaoyang1015

    Joined:
    Nov 22, 2016
    Posts:
    6
    Manual gear, put in first gear, do not step on the accelerator to release the clutch, the vehicle should move forward
     
  19. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    I assume we are discussing vehicle creep that is characteristic to torque converter auto transmissions? There is no such option currently but one quite easy and functional workaround would be to apply a small forward force to the vehicle Rigidbody if the transmission gear is >0.
    Something like this:
    Code (CSharp):
    1. if(vehicleController.powertrain.transmission.gear > 0)
    2. {
    3.    vehicleController.vehicleRigidbody.AddForce(vehicleController.forward * vehicleController.vehicleRigidbody.mass * 0.05f);
    4. }
    Where the 0.05f is some constant coefficient that determines the amount of creep. Rigidbody mass was added as a coefficient to keep the acceleration constant independently of mass.
     
  20. chaoyang1015

    chaoyang1015

    Joined:
    Nov 22, 2016
    Posts:
    6
    I apply a little throttle such as 0.1, and then I see the engine speed continue to rise by itself
     
  21. chaoyang1015

    chaoyang1015

    Joined:
    Nov 22, 2016
    Posts:
    6
    How do I put NWH Vehicle Physics 2 into my own NPM Unity Packages
     
  22. chaoyang1015

    chaoyang1015

    Joined:
    Nov 22, 2016
    Posts:
    6
    Thank you, I want to use NWH Vehicle Physics 2 to simulate the power system of a traditional manual transmission car, but it is still not enough simulation, the work team is working hard. :p
     
  23. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    That is correct. If in neutral gear applying 10% throttle will get engine to go into quite high revs since there is no load. With the transmission engaged and no drag (are you using aerodynamic drag module?) and on flat ground it will keep accelerating. If you use aerodynamic drag module or increase drag on the wheels (to approximate rolling friction) it will accelerate up to a point where engine power equals total drag. In fact most cars are driven with <30% throttle most of the time.
     
  24. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    Hello great job. The physics is great. I'm trying to implement some kind of mature wear and tear. Do you have any help for me
     
  25. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    As in power loss with wear? Or handling degradation?
    Power loss can be done through a simple power modifier added to the engine (that is how the damage does it, basically a callback that is called by the engine which requires a power coefficient - 1 for same, >1 for power increase, <1 for power decrease). Otherwise you could just set the damage manually instead of using the DamageHandler. I will need more details for a better answer.
     
  26. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    I have just merged all the camera scripts into a single universal camera (name CameraMouseDrag will remain just to prevent any import / upgrade issues). It is functionally very similar to the current CameraMouseDrag but has an option to switch between 1st person and 3rd person modes and adds the functionality of camera shake from CameraOnboard. There were a few requests for CameraOnboard that can be rotated but I think that this is a better approach and now this universal camera can both rotate and pan in both 1st and 3rd person mode.

    This is the final product and will replace all the other camera types in the future:
     
    dsilverthorn likes this.
  27. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    706
    This will then be the same for DWP2 I assume, so they will integrate smoothly?
     
  28. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    The camera scripts are already the same between the two so yes, with the next update both will get the updated camera script.
     
  29. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    706
    Awesome, I figured it was, but wanted to verify. ;)
    Keep up the great work!:)
     
  30. Docboy

    Docboy

    Joined:
    Sep 11, 2013
    Posts:
    11

    2021/01/28 Still with the error using v1.5.1


    InvalidOperationException: Synclists can only be modified at the server
    Mirror.SyncList`1[T].AddOperation (Mirror.SyncList`1+Operation[T] op, System.Int32 itemIndex, T oldItem, T newItem) (at Assets/Mirror/Runtime/SyncList.cs:118)
    Mirror.SyncList`1[T].Add (T item) (at Assets/Mirror/Runtime/SyncList.cs:273)
    NWH.VehiclePhysics2.Multiplayer.MirrorMultiplayerVehicle.Initialize () (at Assets/NWH/Vehicle Physics 2/Scripts/Multiplayer/Mirror/MirrorMultiplayerVehicle.cs:38)
    UnityEngine.Events.InvokableCall.Invoke () (at <e414e10bfe5f45729ff122f3359de21b>:0)
    UnityEngine.Events.UnityEvent.Invoke () (at <e414e10bfe5f45729ff122f3359de21b>:0)
    NWH.VehiclePhysics2.VehicleController.Start () (at Assets/NWH/Vehicle Physics 2/Scripts/Vehicle/VehicleController.cs:387)


    The error happend only in the client, got two instance of the project in parallel, the transform unsyncs and after a little time it updates and resyncs to the server

    Could you Help???
     
  31. obeatgamer

    obeatgamer

    Joined:
    Apr 27, 2020
    Posts:
    6
    Can this assets be used for a hovercar vehicle physics??? Because I've tried to use the Unity Tutorial HoverCar with twisted loop track, but it doesn't work well. If I set the angular drag to 3, as in the tutorial, when the vehicle starts to climb the twist, it comes spinning around the Y-axis forever....If I increase the angular drag to 30, it stops to spin...but grabs to walls and it doesnt the best result as possible....Its frustrating so much...because anyone tech this on any tutorial....
     
  32. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    This has been solved on Discord and the fix will ship in a few days with the 1.5.4 update.
     
  33. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    You could and two customers so far that I know of used it for such application but the asset has not been made for this usage and custom solution would work better. If you use it for a hovercraft you will essentially have something similar to car driving on ice, with invisible wheels. And it will not work well on rocky/bumpy terrain.
     
  34. hubaleque

    hubaleque

    Joined:
    Jan 25, 2019
    Posts:
    3
    Hello, I'm using a custom sound creation program called FMOD Studio, it allows you to create functions for certain sound effects, and then import it into Unity and use those functions, one of them is the RPM effect, with that the reality of the audio the cars are very cool and realistic. I was wondering how do I integrate this in the NHW VEHICLE, I tried to find RPM variables or even NWH Class (Script) and I didn't have much success, could you give me any suggestions on how I can find the value of the RPM variable to perform this sound effect?
     
  35. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    You can get all the powertrain-related variables through the Powertrain class, e.g.:
    myVehicleController.powertrain.engine.RPM;
     
    hubaleque likes this.
  36. prg-liulie

    prg-liulie

    Joined:
    Dec 23, 2017
    Posts:
    12
    The car would vibrate sometimes, especially when it is slowing down. It looks like the physics solver is not always stable. Is there any way to fix this problem?
     
  37. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    This should really not be an issue with v1.5 or newer. That said, I would check that the dimensions are correct under Settings tab and click on the button there to re-calculate inertia. If your vehicle has wheels that are far out from the body increasing inertia will help drastically. And lastly the Powertrain > Wheel Groups > Anti Roll Bar Force being too high or damper values being very high can have the effect but I would check the inertia first.
     
  38. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    90
    Hello, Aron!

    I have some problems with “Apply Force To Others”, I think it applies wrong forces.

    Please, look at screenshot – I have bridge with Hinge Constraint.
    If try to drive on it - behavior is wrong. Downforce is not applied to bridge.


    Code (CSharp):
    1.  if (hasHit && _hasHitARigidbody && applyForceToOthers)
    2.             {
    3.  
    4.                 _hitRigidbody.AddForceAtPosition(-_totalForceThisUpdate, wheelHit.point);
    5.             }

    Its obvious from debug output that -totalForceThisUpdate is wrong force to apply to another rididbody.
    What do you think?
     

    Attached Files:

    Last edited: Feb 22, 2021
  39. isNewBird

    isNewBird

    Joined:
    Mar 27, 2019
    Posts:
    14
    Hello, can you recommend a Cvt Gear Ratios for a truck?
    Because the truck I set up according to the documentation doesn't run.
    thank you
     
  40. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    It could be that with the introduction of substepping a bug was introduced that would cause this but the force is the correct one to apply. I have added this to Trello under the list of things to check for the next update which will be out in ~week.
     
  41. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    I would suggest and alternative that works better than the CVT code. Set up a truck with one forward gear and one reverse gear and enable torque converter under the Transmission tab with relatively low slip torque value (start with 100, increase until satisified). I might look into making this an official way to do CVT transmission since a few customers have used it this way and the result is good.
     
  42. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    90
    Thank you, Aron!

    Total force that applied to contacted rigid body is sum of surface forces.
    _totalForceThisUpdate += _surfaceForceVector;

    I understand some kind of downforce (m*g) should be applied also.
    I did not find in code where mass of wheel, vehicle, angle of vehicle body is taken into account.

    Attached screenshot visualize force (long green line) that applied to underline object.
    No downforce component at all, moreover - force is upward, and bridge is moving up instead of moving down)

    I am sorry, do not understand why its correct.
     

    Attached Files:

    Last edited: Feb 23, 2021
  43. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    I have confirmed that this is a bug and have sent you the correct script. Check your PM.
    The fix will ship with update v1.6 in about a weeks time.
     
  44. liulie-bytedance

    liulie-bytedance

    Joined:
    Mar 24, 2020
    Posts:
    1
    Thanks very much! The vibrating is due to inertia as expected. :)
     
  45. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    NWH Vehicle Physics 2 v1.6 is on the way with the following changes:
    • Added .asmdefs to improve compilation times. With the upcoming updates all NWH assets will feature asmdefs.
    • Major changes to the skidmark system for increased performance and stability. Skidmark settings are now adjustable at runtime.
    • Rework of CVT transmission.
    • Fixed modules initializing twice.
    • Fix brake smoothing not being used.
    • Fixed left and right enter-exit points being swapped inside the vehicle setup wizard.
    • Fixed steering deadzone when returnToCenter is disabled.
    • Fixed wheel damage not working properly.
    • Fixed WheelController issue where the longitudinal force coefficient would increase the actual force applied instead of increasing the maximum tractive force, resulting is higher power output than what is generated by the engine when value of >1 was used.
    • Fixed WheelController "ApplyForceToOthers" option applying excessive lateral force to the target object.
    • Fixed NRigidbody substeps get initialized to 1 in all cases. This affects only standalone WheelController setups since substeps in NVP2 are set through the VehicleController which overwrites the initial value.
    • Fixed WheelController Visual transform scale affecting the Rim Collider scale.
    • Upshift RPM of the TransmissionComponent is now limited to a value lower than the engine rev limiter RPM. This prevents issues with vehicle not upshifting when target upshift RPM is too high.
    • Updated clutch settings on the Semi truck to prevent stalling when going from 1st to reverse and vice versa due to slow clutch release.
    • Other minor bug fixes and improvements.
    Note: A clean import will be required. Customers that have more than one NWH asset will have to update them simultaneously due to the restructuring of the common directory. Updates for NVP2, DWP2 and WC3D will be released at the same time.
     
  46. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    39
    Hey, just thought this can have a few hints here and there to optimize this great stuff even further, like batch raycasts:


    Thanks for the status update, very great news. As I'm going to work on a car game very soon, every piece of these updates are very welcome. ;)
     
  47. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    Thank you for the video. Pretty much everything from there has been implemented for at least 2 years, except for per-rigidbody solver settings but then I am using my own physics sub-stepping so that does not play a big role in normal use case.
     
  48. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    39
    That's cool.
     
  49. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,350
    Since all the NWH assets have been updated to use assembly definitions here is a disclaimer to avoid confusion when updating:

    This asset uses Assembly Definition (.asmdef) files. There are many benefits to assembly definitions but a downside is that the whole project needs to use them or they should not be used at all.

    • If the project already uses assembly definitions accessing a script that belongs to this asset can be done by adding an reference to the assembly definition of the script that needs to reference the asset. E.g. to access WheelController adding a NWH.WheelController reference to MyProject.asmdef is required.
    • If the project does not use assembly definitions simply remove all the .asmdef files from the asset after import.
     
  50. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    39
    Let me add a quick link here: https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html
     
unityunity