Physics Material
Physics materials can be created by right-clicking anywhere in the Inspector panel or by clicking between the + button:
Creating by Code
Physics materials can also be instantiated by code:
Physics material properties are shown in the following figure:
When in contact with other surfaces, these coefficients are used to calculate the corresponding friction and force of restitution.
Currently, physics materials are set on a collider basis, and each Collider has a Material property (when not set, the Collider will refer to the default physics material in the physics system).
Applying to Collider is also divided into two ways: editor operations and code operations.
For in-editor operations, simply drag and drop the asset into the cc.PhysicalicMaterial property box, as shown below.
Operate in the code:
In the physics system, physics materials have two states, shared materials and instanced materials.
Shared material: Different colliders that share the same material, and modifications to that material affect all colliders holding that material. By default, colliders are initialized with the engine’s default physics material. This can be accessed through , with the following code example.
Instanced material: Only used by this collider, modifying this material will not affect other colliders.
The following code demonstrates how calling on a collider changes the material to an instanced state when the physics material is in a shared state.