Variable Center of Mass
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.
- Adds an option to adjust the center of mass and inertia tensor of the vehicle
Rigidbody
through the inspector. In Unity 2023 and newer this can be done through theRigidbody
inspector.
- It also has a
MassAffector
feature where the mass, center of mass and inertia can be impacted byMassAffector
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 notRigidbodies
. 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.- The variable part of the name comes from the ability of the script to adjust the mentioned parameters at runtime through
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.
Usage
- Attach the
MassAffector
(or any script inheriting fromIMassAffector
to aGameObject
that is a child of the vehicle. - Tick
Use Mass Affectors
on theVariableCenterOfMass
component. - Untick the
Use Default …
for the properties that theMassAffector
s should affect.