Physical Material
The Physical Material asset is used to define the response of a physical object when interacting dynamically with the world.
Create physical material
To create a new physical material asset, simply navigate to the Content directory in the Content window, then right-click and choose option New -> Physics -> Physical Material. Specify its name and press Enter.
Use physical material
Physical materials are used by the colliders to define their surface properties. You can set the collider material by dragging the asset right into the Material property. Alternatively, you can modify the material at runtime using C# API (see Collider.Material property).
SFX or VFX based on material type
Every Physical Material contains a Tag
property which identifies it for the gameplay. For example, it can be used to distinguish material types to play matching sound or visual effects when a player walks on a surface of a given type (eg. wood or grass).
Example code:
// Event called by Anim Event
private void OnFootstep(Vector3 footLocation)
{
// Raycast at foot location to detect surface over which character walks over
var offset = 10.0f;
var maxDistance = 100.0f;
if (Physics.RayCast(footLocation + Vector3.Up * offset, Vector3.Down, out RayCastHit hitInfo, maxDistance))
{
// Get surface under floor
if (hitInfo.Collider is Collider collider && collider.Material)
{
var material = (PhysicalMaterial)collider.Material.Instance;
if (material.Tag == "Surface.Wood")
{
// play sfx/vfx...
}
}
}
}
Properties
Property | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Friction | The friction value of surface, controls how easily things can slide on this surface. The default value is 0.7 . |
||||||||||
Friction Combine Mode | The friction combine mode, controls how friction is computed for multiple materials. Possible options:
|
||||||||||
Restitution | The restitution or 'bounciness' of this surface, between 0 (no bounce) and 1 (outgoing velocity is same as incoming). The default value is 0.3 . |
||||||||||
Restitution Combine Mode | The restitution combine mode, controls how restitution is computed for multiple materials. Possible options:
|
||||||||||
Density | Physical material density in kilograms per cubic meter (kg/m^3). Higher density means a higher weight of the object using this material. Wood is around 700, water is 1000, steel is around 8000. | ||||||||||
Tag | Physical material tag used to identify it (eg. Surface.Wood ). Can be used to play proper footstep sounds when walking over object with that material. |