Class GroundDetectionPreset
Shared ground detection configuration for vehicles. This ScriptableObject contains SurfaceMaps that map terrain textures and object tags to surface types, plus particle prefabs and fallback settings.
Share this preset across vehicles to avoid configuring ground detection on each one. Typically one preset is created per scene or project, though multiple presets can be used for different vehicle types or environments.
The preset manages:
- Surface detection mappings (terrain textures and object tags to surface properties)
- Particle effect prefabs for dust/smoke and surface chunks
- Fallback surface preset for unmatched surfaces
- Shared configuration across multiple vehicles
Create via: Right-click in Project window > Create > NWH > Vehicle Physics 2 > Ground Detection Preset
Essential setup:
- Assign a fallback surface preset (required)
- Configure surface maps for terrain textures and object tags
- Set up particle prefabs for visual effects (optional)
- Assign to vehicle's GroundDetection component
Workflow:
- Create one or more SurfacePresets defining properties for each surface type
- Create SurfaceMaps to link terrain textures/tags to those presets
- Assign this preset to vehicles that should use these surface definitions
Namespace: NWH.VehiclePhysics2.GroundDetection
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
[CreateAssetMenu(fileName = "NWH Vehicle Physics 2", menuName = "NWH/Vehicle Physics 2/Ground Detection Preset", order = 1)]
public class GroundDetectionPreset : ScriptableObject
Fields
chunkPrefab
Particle system prefab for dirt, stones and debris thrown behind wheels on soft surfaces. Configure the system to emit suitable chunk particles. Used when SurfacePreset.emitChunks is enabled for a surface type.
Leave null if no chunk effects are needed. The same prefab is used for all surface types that enable chunk emission, with individual chunk properties controlled by the SurfacePreset settings (emission rate, lifetime, distance).
Typical setup:
- Particle system with 3D mesh renderer (stones, dirt clumps, debris)
- Physics simulation with gravity and collision
- Short lifetime (0.5-2 seconds)
- Emission controlled by code based on wheel slip and speed
Declaration
[Tooltip("Prefab of the particle system for generating surface chunks / dirt that gets thrown behind the wheel when going over soft surface.")]
public GameObject chunkPrefab
Field Value
| Type | Description |
|---|---|
| GameObject |
fallbackSurfacePreset
Surface preset used as a fallback when no surface maps match the current terrain texture or object tag. Keeps friction and surface properties valid when no surface matches.
REQUIRED: Assign this field for ground detection to work. Usually use a generic preset for the scene's most common surface type (e.g., asphalt, grass, or a neutral preset).
The fallback is used when:
- No terrain textures match any SurfaceMap
- No object tags match any SurfaceMap
- Wheel is on an untagged object that isn't a terrain
- To prevent null reference errors
Use a moderate friction preset that works reasonably well on most surfaces.
Declaration
[Tooltip("Surface preset used when there are no matches in the surfaceMaps list for the current surface.")]
public SurfacePreset fallbackSurfacePreset
Field Value
| Type | Description |
|---|---|
| SurfacePreset |
particlePrefab
Particle system prefab for generating dust or smoke effects from wheel contact with surfaces. The system generates dust (for sand, gravel, dirt) or smoke (for asphalt, concrete) depending on the surface type and ParticleType setting in the SurfacePreset.
Used when SurfacePreset.emitParticles is enabled. The particle color and other properties are controlled by individual SurfacePreset settings. Leave null if no particle effects are needed.
Typical setup:
- Particle system with billboard renderer
- Color and alpha controlled by SurfacePreset
- Emission rate controlled by wheel slip (smoke) or speed (dust)
- Velocity inheritance from wheel motion
- Fade out over lifetime
The same prefab is used for all surfaces, with appearance modified by SurfacePreset parameters.
Declaration
[FormerlySerializedAs("dustPrefab")]
[Tooltip("Prefab of the particle system for generating dust as a result of traveling over sand, gravel, etc.")]
public GameObject particlePrefab
Field Value
| Type | Description |
|---|---|
| GameObject |
surfaceMaps
Collection of surface maps that define how terrain textures and object tags are mapped to surface presets. Each SurfaceMap represents a unique surface type and contains:
- Lists of terrain texture indices that represent this surface
- Lists of object tags that should be treated as this surface
- Reference to the SurfacePreset defining surface properties
The ground detection system iterates through this list to find matches for the current wheel contact. Order matters for tag checking: earlier entries take priority in case of conflicts.
Setup workflow:
- Create SurfacePresets for each surface type (asphalt, grass, dirt, etc.)
- Add SurfaceMaps to this list
- Configure each SurfaceMap with terrain texture indices or object tags
- Assign the appropriate SurfacePreset to each SurfaceMap
Example configuration:
- SurfaceMap "Asphalt": texture index 0, tag "Road", SurfacePreset with high friction
- SurfaceMap "Grass": texture indices 1,2, tag "Grass", SurfacePreset with medium friction
- SurfaceMap "Sand": texture index 3, tag "Sand", SurfacePreset with low friction and dust particles
Declaration
[Tooltip("Surface maps - each represents a single ground surface.")]
public List<SurfaceMap> surfaceMaps
Field Value
| Type | Description |
|---|---|
| List<SurfaceMap> |