Bird
Raised Fist0
Unityframework~10 mins

Physics materials (friction, bounce) in Unity - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Physics materials (friction, bounce)
Create Physics Material
Set Friction and Bounce
Assign to Collider
Run Physics Simulation
Observe Object Behavior
Friction slows sliding
Bounce affects collision rebound
This flow shows how a physics material is created, configured with friction and bounce, assigned to an object, and then affects the object's physical behavior during simulation.
Execution Sample
Unity
var mat = new PhysicMaterial();
mat.dynamicFriction = 0.5f;
mat.bounciness = 0.8f;
collider.material = mat;
This code creates a physics material, sets friction and bounce, and assigns it to a collider.
Execution Table
StepActionVariable/PropertyValueEffect
1Create PhysicMaterialmatnew PhysicMaterial()Material object created
2Set dynamicFrictionmat.dynamicFriction0.5Moderate friction set
3Set bouncinessmat.bounciness0.8High bounce set
4Assign material to collidercollider.materialmatCollider uses new material
5Run simulationObject behaviorSliding slows, bounces on collisionFriction and bounce affect physics
6Object hits surfaceBounce effectRebounds with 80% energyObject bounces back
7Object slidesFriction effectSpeed reduces due to 0.5 frictionObject slows down
8Simulation ends--Physics material effects observed
💡 Simulation ends after object interaction with surface using assigned physics material
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
matnullPhysicMaterial instancedynamicFriction=0.5bounciness=0.8Assigned to colliderUsed in simulation
collider.materialnullnullnullnullmatmat
Key Moments - 3 Insights
Why does the object bounce back after hitting the surface?
Because the physics material's bounciness is set to 0.8 (see execution_table step 3 and 6), the object rebounds with 80% of its collision energy.
How does friction affect the object's sliding speed?
The dynamicFriction value of 0.5 (execution_table step 2 and 7) slows down the object's sliding by reducing its speed over time.
What happens if the physics material is not assigned to the collider?
Without assignment (step 4), the collider uses default physics settings, so friction and bounce effects from the material won't apply.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what property is set and what is its value?
AdynamicFriction = 0.8
Bbounciness = 0.8
CdynamicFriction = 0.5
Dbounciness = 0.5
💡 Hint
Check the 'Variable/Property' and 'Value' columns at step 3 in execution_table.
At which step is the physics material assigned to the collider?
AStep 4
BStep 5
CStep 2
DStep 1
💡 Hint
Look for the action 'Assign material to collider' in execution_table.
If dynamicFriction was set to 0, what would happen to the object's sliding speed?
AIt would bounce higher
BIt would slow down faster
CIt would not slow down due to friction
DIt would stop immediately
💡 Hint
Refer to key_moments about friction effect and execution_table step 7.
Concept Snapshot
Physics Materials in Unity:
- Create PhysicMaterial object
- Set dynamicFriction (slows sliding)
- Set bounciness (controls bounce)
- Assign material to collider
- Physics engine uses these during simulation
- Friction reduces speed, bounce rebounds object
Full Transcript
This visual execution shows how to create and use physics materials in Unity. First, a PhysicMaterial object is created. Then, its dynamicFriction and bounciness properties are set to control sliding resistance and bounce behavior. The material is assigned to a collider component on an object. When the physics simulation runs, the object interacts with surfaces using these settings. Friction slows the object's sliding speed, and bounciness causes it to rebound after collisions. The execution table traces each step, showing variable changes and effects. Key moments clarify why bounce happens and how friction works. The quiz tests understanding of property settings and their impact on physics behavior.

Practice

(1/5)
1. What does a Physics Material in Unity primarily control?
easy
A. The size of a collider
B. The color of a game object
C. The speed of a Rigidbody
D. Friction and bounce behavior of colliders

Solution

  1. Step 1: Understand the role of Physics Materials

    Physics Materials are used to define how surfaces interact physically, mainly controlling friction and bounce.
  2. Step 2: Identify what Physics Materials affect

    They affect colliders by changing friction (slipperiness or stickiness) and bounce (how much objects rebound).
  3. Final Answer:

    Friction and bounce behavior of colliders -> Option D
  4. Quick Check:

    Physics Material = friction and bounce control [OK]
Hint: Physics Materials change friction and bounce, not visuals [OK]
Common Mistakes:
  • Confusing Physics Material with visual materials
  • Thinking it controls Rigidbody speed
  • Assuming it changes collider size
2. Which of the following is the correct way to assign a Physics Material to a Collider in Unity using C#?
easy
A. collider.material = myPhysicsMaterial;
B. collider.physicsMaterial = myPhysicsMaterial;
C. collider.physicMaterial = myPhysicsMaterial;
D. collider.physicsMaterial2D = myPhysicsMaterial;

Solution

  1. Step 1: Recall the correct property name for Physics Material

    In Unity, the Collider component uses the property 'material' to assign a Physics Material.
  2. Step 2: Check the options for correct syntax

    collider.material = myPhysicsMaterial; uses 'collider.material', which is correct. Other options use incorrect property names or 2D-specific properties.
  3. Final Answer:

    collider.material = myPhysicsMaterial; -> Option A
  4. Quick Check:

    Collider.material assigns Physics Material [OK]
Hint: Use collider.material to assign Physics Material [OK]
Common Mistakes:
  • Using 'physicsMaterial' instead of 'material'
  • Confusing 3D and 2D collider properties
  • Misspelling 'physicMaterial'
3. Consider the following C# code in Unity:
PhysicsMaterial2D bouncyMaterial = new PhysicsMaterial2D();
bouncyMaterial.bounciness = 1.0f;
Collider2D col = gameObject.GetComponent<Collider2D>();
col.sharedMaterial = bouncyMaterial;

Rigidbody2D rb = gameObject.GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(0, -10);
What will happen when this object hits the ground?
medium
A. It will bounce back with the same speed it hit the ground
B. It will stick to the ground without bouncing
C. It will bounce but lose some speed
D. It will ignore collisions and pass through the ground

Solution

  1. Step 1: Analyze the Physics Material bounciness

    The bouncyMaterial has bounciness set to 1.0, which means full bounce with no energy loss.
  2. Step 2: Understand the effect on collision

    Assigning this material to the collider means the object will bounce back with the same speed it hit the ground.
  3. Final Answer:

    It will bounce back with the same speed it hit the ground -> Option A
  4. Quick Check:

    Bounciness 1.0 means full bounce [OK]
Hint: Bounciness 1 means full bounce, no speed lost [OK]
Common Mistakes:
  • Assuming bounciness 1.0 means no bounce
  • Confusing sharedMaterial with material
  • Ignoring Rigidbody velocity effect
4. You wrote this code to make an object slippery:
PhysicsMaterial2D slippery = new PhysicsMaterial2D();
slippery.friction = 0f;
Collider2D col = gameObject.GetComponent<Collider2D>();
col.material = slippery;
But the object still slides slowly. What is the likely mistake?
medium
A. You should set bounciness to 0 instead of friction
B. You assigned the material to 'col.material' instead of 'col.sharedMaterial'
C. The Rigidbody2D's linear drag is causing slow sliding
D. Physics Materials do not affect friction

Solution

  1. Step 1: Check the property used for assignment

    Collider2D uses sharedMaterial property to assign PhysicsMaterial2D, not material which does not exist on Collider2D.
  2. Step 2: Understand the consequence

    Using the wrong property means the custom material with friction=0 is not assigned; default material with friction >0 is used, causing slow sliding.
  3. Final Answer:

    You assigned the material to 'col.material' instead of 'col.sharedMaterial' -> Option B
  4. Quick Check:

    Collider2D.sharedMaterial is the correct property [OK]
Hint: Collider2D: use sharedMaterial, not material [OK]
Common Mistakes:
  • Thinking friction 0 disables all slowing forces
  • Confusing material and sharedMaterial assignment
  • Believing Physics Materials don't affect friction
5. You want to create a bouncy ball that loses some energy on each bounce and slides slowly on the floor. Which settings for Physics Material friction and bounciness should you use?
hard
A. friction = 1.0, bounciness = 1.0
B. friction = 0, bounciness = 1.0
C. friction = 0.8, bounciness = 0.5
D. friction = 0.2, bounciness = 0

Solution

  1. Step 1: Understand desired bounce behavior

    The ball should bounce but lose some energy, so bounciness should be less than 1, e.g., 0.5.
  2. Step 2: Understand desired sliding behavior

    To slide slowly, friction should be moderate to high, e.g., 0.8, to resist sliding.
  3. Final Answer:

    friction = 0.8, bounciness = 0.5 -> Option C
  4. Quick Check:

    Moderate friction and bounciness = slow slide + partial bounce [OK]
Hint: Use moderate friction and bounciness for slow slide and partial bounce [OK]
Common Mistakes:
  • Using zero friction causes too much sliding
  • Using bounciness 1.0 causes full bounce with no energy loss
  • Confusing friction and bounciness values