Creating and Using Physics Materials
Overview
Physics Material is to define the dynamic interaction response between the Game Object and the World Scene. Physics Materials on game objects can be obtained by the scene collision detection feature and returned in their collision results. Physics Materials are created and saved through prefab files and can be extended with more user-defined material properties by means of C++ derived classes.
Creating Physics Materials
Select res in the Project panel, right-click on a blank space in the Resource Preview window to open a shortcut menu, then select New Folder to create one and name it Physics_Material (Any name will do).
Note: Physics materials cannot be created directly in the root directory.
In this directory, right-click on a blank space in the Resource Preview window and click Prefab to create a new physics material.
In the pop-up Pick Parent Class window, select Physics Material and click the OK button.
Enter the name of the Physics Material prefab to be created in the input box of the pop-up window, and click the OK button.
Double-click the created prefab file to open the editing window of this physics material prefab.
The physics material can be edited by modifying related properties In the Details Panel. Physics material created via Prefab -> Physics Material only contains Friction related properties. To add more custom properties to the physics material, create its derived type via C++ inheriting Class LPhysicsMaterial. For example, add different sounds, effects, etc. corresponding to different physics materials.
Properties
Property | Description |
---|---|
Material Name | Name of the physics material |
Dynamic Friction | Dynamic friction coefficient |
Static Friction | Static friction coefficient |
Friction Combine Mode | Select the combination mode of friction. There are the following 4 different modes for calculating the friction when it occurs:
|
Restitution | The spring coefficient of the object. |
Restitution Combine Mode | Select the combination mode of spring. There are the following 4 different modes for calculating the restitution after deformation:
|
After modification, click the button to save.
Applying Physics Materials
In Rigidbody Editor
The material configuration will be saved in the Rigid Body physics resource file.
In the Tree View panel or Scene panel of the Rigidbody Editor, select the collider that needs applying a physics material.
In the Rigidbody Detail panel, expand the Material option under Collider.
In Material File, you can select a physics material prefab file, and it is Empty by default. At this time you can modify the following related properties to modify the collider physics material properties.
If you select a physics material prefab file in Material File, the related properties below will use the preset property values in that physics material by default, and the property names will turn gray and cannot be modified.
In Model Editor
The material configuration will be saved in the model parameter file.
In the Model Editor, select the Model Property panel, and in the Default drop-down box under Physics Material, select an existing physics material prefab.
In Components
The material configuration will be saved in the scene configuration by default, or in the prefab configuration if the component is saved as a prefab.
Select an object in the Hierarchy panel, then select the component in the Inspector panel, find Material under Physics in the properties below, and specify a physics material in Material Override.
If you want to set different physics materials for the specified collider, set it separately in Apply Material To Colliders. If there is no collider with a separately set material, the physics material in Material Override will be used uniformly(The prerequisite for specifying physics materials to a collider is that the component has referenced Rigid Body resources).
Property | Description |
---|---|
Collider Name | The name of the collider that needs configuring a special physics material. |
Physics Material | Specify an existing physics material file. |
Adding Collider Physics Materials
Click the button to add a new collider physics material bar.
Duplicating Collider Physics Materials
Click the button next to the collider physics material bar to duplicate a new physics material bar.
Deleting Collider Physics Materials
Click the button next to the collider physics material bar to delete the current physics material bar.
Click the button next to Apply Material To Colliders to delete all collider physics materials.
In Voxel Terrains
Select the voxel terrain object in the Hierarchy panel, or directly select it in the Level panel, then right-click it to open the shortcut menu, select Find Asset, and go to the directory where the corresponding resource is located in the Project panel.
Double-click the voxel terrain file in the Resource Preview window to open the Voxel Terrain Editor.
Click Ecology in the Voxel Terrain Editor, then in the Ecology panel, select the ecology that needs adding a physics material in Planetary Ecology, and double-click it to open the editing window for that ecology.
Find PhysX Reference in the Edit Ecology panel of the ecology editing window, and drag the physics material to be referenced from the Resource Preview window into PhysX Reference.
After dragging:
Click the button to save.
Priority of Physics Materials
The priority of effectiveness for physics materials specified on components, models or in physics resources (Rigidbody Editor) is: components > models > physics resources.
For example, a physics material specified on a component overrides those specified on a model and in a physics resource, and a physics material on a model overrides that specified in a physics resource.
Displaying Effects
The following is a display of simple effects of physics materials.
After making Rigid Body resources (creating colliders) for the box model, drag the box model from the Resource Preview window into the Level panel and adjust its position (Refer to Rigidbody Editor to create a Rigid Body resource).
Make a Rigid Body resource for the box model:
Drag the box model into the Level and adjust its position:
Select box in the Hierarchy panel, then select StaticMeshComponent(Inherited) in the Inspector panel (this model component uses the Rigid Body resource created in the Rigidbody Editor by default), and check Simulate Physics in the Physics panel below.
Configure physics materials for the object's Rigid Body/model/component according to the method provided above for applying a physics material in the Rigidbody Editor/in the Model Editor/on the Component (The priority of effectiveness is: component > model > Rigid Body resource).
Drag a curved_stair model from the Resource Preview window into the Level panel and adjust its position to the bottom of the box.
Effect I
Physics material prefab properties:
Effect II
Physics material prefab properties:
Effect III
Physics material prefab properties: