Lesson 4 of 9 · 27m
Physics, Rigidbodies, and Collision Reality
Build reliable movement and collision behavior by understanding rigidbody modes, collision matrices, continuous detection, and physics timestep.
Unity physics bugs have a special flavor: the game looks fine for twenty minutes, then a box tunnels through a wall at high speed or a player vibrates into orbit because two colliders disagree by a millimeter. Physics is a simulation system with rules. It is not a magical collision service attached to meshes.
Choose the right body type
A collider without a Rigidbody is static. A collider with a Rigidbody is dynamic. In 2D, Rigidbody2D has body types that make the intent explicit:
Dynamic simulated with mass, forces, gravity, collisions
Kinematic moved by your code, still generates interactions
Static never expected to moveMoving a static collider by changing its transform is expensive in 3D and conceptually wrong everywhere. If it moves meaningfully, give it the right body type.
Move physics objects through the physics API
Do this:
private void FixedUpdate()
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}Not this:
private void Update()
{
transform.position += velocity * Time.deltaTime;
}The second version teleports the visual transform outside the simulation. Unity will reconcile it during physics, often by producing penetration correction, missed collisions, or jitter.
Understand collision events
Callbacks depend on body types, collider settings, and the collision matrix:
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.TryGetComponent(out Health health))
health.TakeDamage(impactDamage);
}A trigger uses OnTriggerEnter2D; a solid collider uses OnCollisionEnter2D. Trigger events are sensors, not physical blocking contacts. If neither object has a dynamic or kinematic body configured correctly, you may get silence rather than an error.
Fast objects tunnel
Discrete collision checks sample positions at fixed steps. A projectile moving 40 units per second at a 50 Hz timestep travels 0.8 units per step — straight through a thin wall. Use continuous collision detection for projectiles:
rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous;For very fast hitscan-like attacks, do not use a physical projectile at all. Raycast:
var hit = Physics2D.Raycast(origin, direction, range, targetMask);
if (hit.collider != null)
ApplyHit(hit.collider, hit.point);Field notes
- Colliders should match gameplay shape, not visual detail. A capsule is often better than a pixel-perfect polygon.
- Never solve stacking jitter by randomly increasing solver iterations before checking scale, mass ratios, timestep, and transform-driven movement.
Was this lesson helpful?