Physics Materials and Effectors
Desliza para mostrar el menú
So far, our player falls thanks to gravity and stops when it reaches a platform because of colliders. But when it lands, it just stops and that doesn't feel very satisfying.
Fortunately, Unity lets us add bounciness to objects using a Physics Material 2D.
Step 1: Create a Physics Material 2D
- Select the platform object and look at its collider. There's a slot for a Physics Material 2D;
- It's good practice to keep things organized, so create a folder for physics materials in your Project tab;
- Right-click inside the folder, go to Create → 2D → Physics Material 2D;
- Name your material something descriptive (e.g.,
PM_platform).
Step 2: Adjust Physics Material Properties
Select the physics material and look in the Inspector. Two important values:
- Friction: determines how slippery a surface is;
- Bounciness: determines how much objects bounce when they hit it.
Step 3: Assign the Physics Material
- Select the platform object;
- Drag the physics material into the Physics Material 2D slot on the collider.
Now your platform will use the material's properties.
- Set bounciness = 1 → the player bounces back to the starting height;
- Set bounciness < 1 → the player bounces lower each time and eventually stops;
- Set bounciness > 1 → the player bounces higher each time, endlessly.
For now, we'll use 1.
Step 4: Prevent Bouncing Problems with the Platform Effector
Sometimes, when the player tries to bounce up onto another platform, they hit the bottom instead of landing on top.
Unity provides a fix: the Platform Effector 2D.
- Select the platform object → Add Component → Platform Effector 2D.
- A warning will appear. Go back to the platform's collider and check Used by Effector;
- Now, when the player moves up through the platform from below, it won't block the bounce, but it will still land properly from above.
Step 5: Adjust the Player Collider if Needed
Sometimes the player might appear to bounce off a platform even if their feet aren't aligned with it.
- This happens if the player's collider is too wide;
- Make the collider narrower so it matches the width of the player's feet;
- Now the bounce only happens when the player actually lands on the platform.
Step 6: Experiment!
Physics Materials and colliders are very flexible.
- Try different bounciness values;
- Try different gravity scales and linear damping values;
- Resize and reposition colliders.
This lets you create all kinds of gameplay effects and makes your endless jumper feel alive and satisfying.
Your player can now bounce, land, and interact realistically with platforms, a fun foundation for more complex movement and mechanics.
1. What does the Bounciness value in a Physics Material 2D control?
2. Why do you use a Platform Effector 2D on a platform in Unity?
3. What should you do if the player bounces off a platform even when their feet don’t touch it?
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla