Vehicle Damage Controller
Last updated
Last updated
Vehicle Damage Controller is responsible for mesh deformation and controls other damage system related scripts, like PartDamageHandler and VehicleAttachmentsAligner.
Mathematics and Burst packages must be installed, otherwise the script will not be available at all.
You must enable the read/write property in the import settings on mesh to enable mesh deformation.
VehicleDamageController requires CollisionHandler and MeshFilter to apply deformation to the mesh.
Deformation Persists is a boolean that makes the deformation stay in memory, so it is saved between scenes.
Expand the "Properties" foldout.
Main Mesh Filter
The mesh of the vehicle's body.
Additional Mesh Filters Array
The meshes of other vehicle body parts that will take part in deformation. For example, bumpers and doors, if those have separate meshes
Body Strength
Defines how resilient the vehicle is to deformation. [0.001 - 0.999], where 0.999 makes the vehicle suffer almost no damage.
Damage Radius Multiplier
When a collision occurs, the CollisionHandler sends the CollisionImpactInfo for every collision point. One of the properties is the distance to the previous point, which defines the area of the collision. Multiplier affects this area's size.
Additional Damage Radius
Added radius to the area outside the normal damage radius. Noise is applied to the vertices outside the normal damage radius, so too big value can cause weird deformation.
Max Deform Depth
The maximum distance the vertice can be moved from the original position.
At this point, the standard setup for the basic vehicle deformation is complete.
For better performance you can split the vehicle mesh into possible collision areas, so that the amount of work when collision occurs will be lowered. Learn how to create CollisionAreasDataSO here. Note that as of version 3.3.0, this works only for a single mesh deformation.
After you've created the CollisionAreasDataSO, assign it to the VehicleDamageController.
Two booleans will appear.
Collision Areas Optimization
Using the CollisionAreasDataSO, find the area where the collision occured and apply deformation only to the vertices inside it.
Deform Affected Collision Areas
Find all the other areas that are inside the resulting collision damage radius and apply deformation to them as well.
Optionally, you can assign the "PartDamageHandler" and "AttachmentsAligner" components. These components don't work by themselves and require to be assigned to the "VehicleDamageController".