Class CrashComponent
Plays a vehicle collision sound at the contact point, with volume scaled by collision velocity magnitude. Chooses randomly from the assigned audio clips.
Inherited Members
Namespace: NWH.VehiclePhysics2.Sound.SoundComponents
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class CrashComponent : SoundComponent
Fields
pitchRandomness
Amount of random pitch variation applied to each collision sound. Randomizes pitch in range [basePitch * (1 ± pitchRandomness)] to make impacts sound unique. Value of 0.4 allows pitch variation between 0.6x and 1.4x base pitch.
Declaration
[Range(0, 0.5)]
[Tooltip("Different random pitch in range [basePitch + (1 +- pitchRandomness)] is set each time a collision happens.")]
public float pitchRandomness
Field Value
| Type | Description |
|---|---|
| float |
velocityMagnitudeEffect
Scales collision velocity into a 0-1 volume ramp, so volume reaches baseVolume at 5 / velocityMagnitudeEffect m/s and every harder impact plays at that same volume. Lower values stretch the ramp and keep volume varying up to higher impact speeds.
Declaration
[Range(0, 5)]
[Tooltip("Higher values result in collisions getting louder for the given collision velocity magnitude.")]
public float velocityMagnitudeEffect
Field Value
| Type | Description |
|---|---|
| float |
Properties
AudioMixerGroup
Gets the Audio Mixer Group this component's AudioSource should output to. Used to route audio through the vehicle's audio mixer for processing and mixing.
Declaration
public override AudioMixerGroup AudioMixerGroup { get; }
Property Value
| Type | Description |
|---|---|
| AudioMixerGroup |
Overrides
ContainerGO
Gets the GameObject container where the AudioSource should be created. Used to position audio sources at specific locations on the vehicle.
Declaration
public override GameObject ContainerGO { get; }
Property Value
| Type | Description |
|---|---|
| GameObject |
Overrides
Priority
Gets the priority level for the AudioSource. Lower values indicate higher priority. Range is 0 (highest) to 256 (lowest). Used by Unity's audio system when the maximum number of audio sources is reached.
Declaration
public override int Priority { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
PlayCollisionSound(Collision)
Plays a collision sound based on impact parameters. Volume is calculated from the collision's relative velocity magnitude and the velocityMagnitudeEffect multiplier. Pitch is randomized based on pitchRandomness. Sound position is set to the first contact point.
Declaration
public void PlayCollisionSound(Collision collision)
Parameters
| Type | Name | Description |
|---|---|---|
| Collision | collision | Unity collision data containing contact points and relative velocity. |
VC_Disable(bool)
Stops and disables the AudioSource belonging to this SoundComponent.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
VC_Enable(bool)
Enables the AudioSource belonging to this SoundComponent.
Declaration
public override bool VC_Enable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
VC_SetDefaults()
Writes default values into every serialized field, and may pull default assets from Resources. Runs on vehicle reset and when the component is first added.
Declaration
public override void VC_SetDefaults()