Skip to main content

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.

image-20230331131819572

In this directory, right-click on a blank space in the Resource Preview window and click Prefab to create a new physics material.

image-20230331131905491

In the pop-up Pick Parent Class window, select Physics Material and click the OK button.

image-20230404132108195

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.

image-20230331161413547

Double-click the created prefab file to open the editing window of this physics material prefab.

image-20230404142703790

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.

image-20230331161532882

Properties

image-20230331142923452

PropertyDescription
Material NameName of the physics material
Dynamic FrictionDynamic friction coefficient
Static FrictionStatic friction coefficient
Friction Combine ModeSelect the combination mode of friction. There are the following 4 different modes for calculating the friction when it occurs:
  • Average: The default combination mode. The average friction value of the object experiencing friction.
  • Min Value: The minimum friction value in the object experiencing friction.
  • Multiply: Product of the friction of the object experiencing friction.
  • Max Value: The maximum friction value in the object experiencing friction.
RestitutionThe spring coefficient of the object.
Restitution Combine ModeSelect the combination mode of spring. There are the following 4 different modes for calculating the restitution after deformation:
  • Average: The default combination mode. The average restitution value of the contact object when deformation occurs.
  • Min Value: The minimum restitution value of the contact object when deformation occurs.
  • Multiply: Product of the restitution value of the contact object when deformation occurs.
  • Max Value: The maximum restitution value of the contact object when deformation occurs.

After modification, click the image-20230331145716244button to save.

image-20230331145747974

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.

image-20230331151544978

In the Rigidbody Detail panel, expand the Material option under Collider.

image-20230331174559981

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.

image-20230403093438889

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.

image-20230403100128062

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.

image-20230403105941750

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.

image-20230404135450072

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).

image-20230404135821822

PropertyDescription
Collider NameThe name of the collider that needs configuring a special physics material.
Physics MaterialSpecify an existing physics material file.
Adding Collider Physics Materials

Click the image-20230403112113338button to add a new collider physics material bar.

image-20230404135906480

Duplicating Collider Physics Materials

Click the image-20230403133649375button next to the collider physics material bar to duplicate a new physics material bar.

image-20230404140018865

Deleting Collider Physics Materials

Click the image-20230403134026417button next to the collider physics material bar to delete the current physics material bar.

image-20230404140052967

Click the image-20230403134518228button next to Apply Material To Colliders to delete all collider physics materials.

image-20230404140118780

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.

image-20230727163654969

Double-click the voxel terrain file in the Resource Preview window to open the Voxel Terrain Editor.

image-20230403140241207

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.

image-20230403140627196

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.

image-20230403171132302

After dragging:

image-20230403171000827

Click the image-20230403171310984button to save.

image-20230403171246286

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:

image-20230406092223652

Drag the box model into the Level and adjust its position:

image-20230404153728278

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.

image-20230404155250035

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.

image-20230404173147702

Effect I

Physics material prefab properties:

image-20230404173651395

Normal

Effect II

Physics material prefab properties:

image-20230404171345504

Elastic

Effect III

Physics material prefab properties:

image-20230404173040065

Slippery