These scripts are shared between NWH Vehicle Physics 2, Dynamic Water Physics 2 and NWH Aerodynamics.
CameraChanger
iterates over all the Camera
s in the VehicleCamera
s list and makes sure that only one camera is active at one time.CameraChanger
component to the Cameras object. This should be an empty object that is a child of vehicle root.Auto Find Cameras
or manually assign cameras to the Vehicle Cameras
list. If Auto Find Cameras
is enabled it is important that all the cameras are placed as children of the object containing CameraChanger
script or otherwise they will not be auto-detected.C
(default value). Check Input Setup for more info.A script that can be attached to any Camera. It tells the vehicle if the camera is inside the vehicle. If it is, low pass filter is applied to imitate the muffled sounds inside the vehicle.
The default camera script. Can be used for both 1st and 3rd person.
VehicleCamera
.Camera
and assign Target
that the camera will follow. If left empty the CameraMouseDrag
will auto-find target VehicleController.
This is a common script shared between all the vehicle focused NWH assets.
Since Unity 2022 this script is no longer needed to adjust center of mass or inertia from the inspector as those settings are now exposed through Rigidbody inspector.
Rigidbody
through the inspector. In Unity 2023 and newer this can be done through the Rigidbody
inspector.MassAffector
feature where the mass, center of mass and inertia can be impacted by MassAffector
s attached to the vehicle. This can be a fuel tank, a piece of cargo, a player, etc. MassAffectors
, despite affecting the Rigidbody properties, are not Rigidbodies
. This allows for things like cargo to affect the vehicle, without having the overhead of Rigidbody collisions/joints/etc.VariableCenterOfMass
is designed to give users more control over the Rigidbody which is usually needed for use with vehicles. This is because Unity assumes all objects/colliders have uniform density and therefore calculates the center of mass and inertia using that assumption. This script allows for tweaking of both of these values to better fit the specific vehicle. Center of mass and inertia tensor, besides mass, have the biggest effect on vehicle handling.IMassAffector
s. There are components attached to different parts of the vehicle that affect the vehicle mass, the center of mass, and inertia but are not Rigidbodies by themselves. Examples of this would be fuel tanks, passengers, cargo, etc.MassAffector
(or any script inheriting from IMassAffector
to a GameObject
that is a child of the vehicle.Use Mass Affectors
on the VariableCenterOfMass
component.Use Default …
for the properties that the MassAffector
s should affect.
IMassAffector
is an interface that can be inherited by any MonoBehavior and the only parameter it stores is mass. If attached as a child (it does not need to be a direct child) this script will modify the parent Rigidbody mass, center of mass and inertia through its mass and position relative to the Rigidbody.
Any values visible in the VariableCenterOfMass
are displayed without the additional weight of the IMassAffector
s and only in play mode do these get applied. The VariableCenterOfMass
will iterate over child IMassAffector
, calculate the new values and apply them to the Rigidbody
each physics update.
Default implementation is MassAffector
which includes all the base fields.
A simple shifting origin script. Moves all objects in the scene to keep the player near the origin once the distance exceeds the Distance Threshold
.
Shifting origin is a commonly used technology in most open-world games to combat the degradation of the quality of physics and visuals far from the origin (~1000 units or more). Since Unity uses floats for storing position data the largest value that can be stored is 7 digits. When the distance is large only a limited number of the digits is available on the right side of the decimal point. That means that at ~100km from the origin the position resolution is only 1cm! By moving the object back to [0, 0, 0] each time that the object gets too far away from the origin, and also moving the whole world with it for the same amount, an illusion of travelling great distances is formed while the player never gets further than some threshold from the origin.
Vehicle changer is used to switch between the vehicles. It supports instant switching or character enter/exit type switching, depending on the Character Based
option.
Auto Find Vehicles
option. Vehicles that have Settings > Register With Vehicle Changer
set to true
will get added to the list.ChangeVehicle
(Input Setup) button will switch to the next vehicle in Vehicles
list. When the last vehicle is reached it will wrap around and start from the first vehicle again.Character Based
switching is enabled the only way to change the vehicle is to exit the current one (some kind of 1st or 3d person character controller is assumed), walk to the next vehicle and press the ChangeVehicle
(Input Setup) button.Character Object
is assigned. This is a GameObject containing the character controller. The asset does not care which character controller is used as it will simply deactivate the character controller GameObject and give the control to the vehicle that is being entered.Enter Exit Tag
, which is EnterExitPoint
by default. Check the demo scene vehicles for the example, e.g. the Niva has the LeftEnterExitPoint only, which means that the character can exit only from the left (driver) side. Duplicate it and move it to the right door position to make entering from the passenger side possible too.