NWH Vehicle Physics 2 is a collection of
VehicleComponents. All aspects of it are a component - sound components, effect components, etc. - they all inherit from
VehicleComponent. The only way that a module is different from an inbuilt component is that it can be added or removed as needed.
Modules carry over state system from the
VehicleComponent which means that each module can be turned on or off, enabled or disabled or have LOD set.
ModuleWrapper. This is a way to work around lack of multiple inheritance in C#. So, to add a module just add its wrapper to the vehicle:
ModuleManagerdrawer. Go to
VehicleControllerto see all of the available modules. This is to avoid cluttering the inspector with a multitude of different editors. Modules can also be filtered by category to make navigation easier.
Each module is wrapped in a MonoBehaviour wrapper called
ModuleWrapper. This is a way to get around lack of multiple inhertance in C#.
VehicleModule inherits from
VehicleComponent, but it also needs to be serialized and for that it needs to be a
MonoBehaviour. The new attribute [SerializeReference] has been present in Unity since 2019.3 and original implementation used that but the amount of bugs and lack of backwards-compatibility with older versions of Unity resulted in the wrappers being used instead.
To add a module use:
Example (adding an ABSModule):
ABSModule absModule = myVehicleController.moduleManager.AddModule<ABSModuleWrapper, ABSModule>();
To get a module use:
Example (getting ABSModule):
ABSModule absModule = myVehicleController.moduleManager.GetModule<ABSModuleWrapper, ABSModule>();
To remove a module use:
Example (removing ABSModule): <code> myVehicleController.moduleManager.RemoveModule<ABSModule>();
For class reference click here.
Scripts ⇒ Vehicle ⇒ Modules ⇒ ModuleTemplatefolder there is an empty example module. Copy
ModuleTemplateto create a starting point for a new module.
ModuleDrawer(a type of
CustomPropertyDrawer) placed in
ModuleDrawerwhich uses NUI editor GUI framework (developed by NWH coding) to render custom property drawers and editors through simplified syntax. This also makes the created module compatible with
Check out this link for NWH Vehicle Physics scripting reference. TODO
Side Cd(Cd = coefficient of drag) fields. Data for different vehicles is available here.
Downforce is calculated in a simplified fashion by applying downforce to a number of points over the vehicle. In the simplest form a single downforce point at the center of the vehicle can be used, or one point at the front and one point at the end of the vehicle.
Downforce Points should be below the
WheelControllerposition, or even as low as the floor of the vehicle. This is because all the force is applied in a single point which, if applied too high, can cause the vehicle to snap oversteer when changing direction.
Max Downforce Speed.
Max Downforce Speedat which it reaches
Module for simulating the fuel system in a vehicle. Fuel consumption gets automatically generated from engine efficiency (average ICE efficiency is used) and fuel energy content. Consumption can be adjusted through
Amountindicates the amount of fuel currently in the tank while
Capacityindicates maximum tank capacity.
TrailerModule works in tandem with
VehicleController that has
TrailerModule is able attach to a
VehicleController that has
Attachment Pointis the point at which the trailer will be attached to the towing vehicle.
Trailer Standis the object which will be enabled if the trailer is detached and vice versa. It prevents the trailer from tipping forward on trailers with only the back axle.
Synchronize Gear Shiftsis enabled the trailer object will be kept in the same gear. This allows for powered trailer or vehicles that are constructed out of two Rigidbodies.
Also check Trailer Hitch module.
TrailerHitchModule can attach a
TrailerModule as a trailer.
TrailerModulecan be present on one vehicle at the same time.
AttachmentPointis the point at which the trailer will be attached. The trailer will be moved so that both trailer and hitch
AttachmentPoints are at the same position. This is where the physics joint gets created.
Also check Trailer module.