In this lesson, you will learn how to fine-tune your player's movement responsiveness by adjusting Physics Materials to control how your character interacts with different ground surfaces.
Understanding Physics Materials
When your character moves across a scene, Unity calculates movement based on the velocity applied to the Rigidbody. However, the feel of that movement—whether your player feels "heavy" and grounded or "slick" and slidey—is determined by Physics Materials.
A Physic Material is an asset you create in your Project window (Right-click > Create > Physic Material). It contains two critical properties:
- Dynamic Friction: How much the object resists movement while already moving.
- Static Friction: How much force is required to start moving an object from a standstill.
Applying Materials to Surfaces
To control character traction, you assign these materials to the Collider components of your environmental objects. For example, if your player walks onto an "Ice" surface, you would assign a material with near-zero friction. If they step onto "Grass," you might increase the friction to provide a snappy, responsive stop.
When your character is moving, Unity’s physics engine multiplies the movement force by the friction values of the ground they are touching. If the friction is high, the character comes to a halt quickly when input stops. If friction is low, the character will continue to slide due to the momentum defined in your movement logic.
// Example: Checking the friction of the current surface
// (assuming you have a Raycast hit detected as covered in lesson 25)
if (groundHit.collider.sharedMaterial != null)
{
float surfaceFriction = groundHit.collider.sharedMaterial.dynamicFriction;
// You can use this value to dampen velocity
// or influence your movement speed multipliers!
}
Balancing Traction and Gameplay
A common pitfall for beginners is setting friction too high, which can cause characters to jitter or get "stuck" on edges. Instead of relying solely on friction, use it to define the environmental feel. Use high friction for solid ground to ensure your character stops immediately upon releasing movement keys, and use low friction for specialized zones like ice or mud to force players to adjust their movement style.
Key Takeaway: Physics Materials allow you to manipulate surface traction globally by assigning unique friction values to your floor colliders, directly influencing how your character stops, starts, and slides across your game world.