قالب وردپرس قالب وردپرس قالب فروشگاهی وردپرس وردپرس آموزش وردپرس

Why Objects Pass Through Walls (Tunneling)

Unity Rigidbody Interpolation Explained
Unity Rigidbody Interpolation Explained: Smooth Movement Without Jitter
February 22, 2026
Unity Physics Layers Best Practices
Unity Physics Layers Best Practices: Organize Collisions Efficiently
February 22, 2026

Why Objects Pass Through Walls (Tunneling)

Why Objects Pass Through Walls

Have you ever shot a bullet, thrown a fast ball, or moved a car quickly in Unity, only to see it pass right through a wall or floor? This frustrating behavior is called tunneling.

It’s a common problem for fast-moving Rigidbody objects. Understanding why it happens and how to fix it is critical for any physics-heavy game.

Why Tunneling Happens

Unity physics runs in fixed steps. By default, FixedUpdate runs every 0.02 seconds (50 Hz). During each step, Unity calculates collisions between positions.

If an object moves too far in a single physics step, it may skip over a collider entirely. The physics engine never detects the collision → the object “tunnels” through.

Think of it as taking big leaps over small obstacles instead of touching them.

Key Factors That Cause Tunneling

  • High speed of the Rigidbody
  • Small collider thickness on walls or obstacles
  • Low fixed timestep
  • Discrete collision detection (default)

Solution 1: Enable Continuous Collision Detection

Rigidbody has a Collision Detection setting. By default, it is set to Discrete, which is fast but can miss collisions.

Change it to:

  • Continuous: For moving objects that collide with static geometry
  • Continuous Dynamic: For moving objects colliding with other moving objects
Rigidbody rb = GetComponent<Rigidbody>();
rb.collisionDetectionMode = CollisionDetectionMode.Continuous;

This instructs Unity to perform extra checks and prevent tunneling.

Solution 2: Reduce Fixed Timestep

Unity physics runs at a fixed interval. Faster updates reduce tunneling.

Default Fixed Timestep = 0.02 (50 FPS)

Consider reducing to 0.01 (100 FPS) in Edit → Project Settings → Time.

  • Pros: more accurate physics
  • Cons: higher CPU usage

Solution 3: Use Thicker Colliders

Thin walls or floors are easier to miss. Increasing thickness reduces the chance of tunneling.

  • Use BoxCollider or CapsuleCollider for walls
  • Avoid extremely thin meshes

Solution 4: Limit Object Speed

If your object is moving extremely fast, even continuous collision detection can fail.

Clamp the maximum velocity:

Vector3 velocity = rb.velocity;
float maxSpeed = 50f;

if (velocity.magnitude > maxSpeed)
{
    rb.velocity = velocity.normalized * maxSpeed;
}

Solution 5: Use Raycasting for Critical Fast Objects

For bullets or projectiles, sometimes physics alone isn’t enough. Use a raycast to detect collisions manually between frames.

RaycastHit hit;
Vector3 move = rb.velocity * Time.fixedDeltaTime;

if (Physics.Raycast(transform.position, rb.velocity.normalized, out hit, move.magnitude))
{
    transform.position = hit.point;
    // Handle collision manually
}
else
{
    rb.MovePosition(transform.position + move);
}

This guarantees detection even for extreme speeds.

Best Practices Summary

  • Use Continuous collision detection for fast-moving Rigidbodies
  • Reduce Fixed Timestep if needed
  • Keep colliders reasonably thick
  • Clamp object speed
  • Consider raycasting for small fast projectiles

Performance Considerations

  • Continuous collision detection is more expensive than discrete
  • Lowering Fixed Timestep increases physics calculations per second
  • Only enable for objects that need it

Final Thoughts

Tunneling is not a bug—it is a consequence of discrete physics simulation. Understanding how Unity performs collision detection allows you to prevent objects from passing through walls while keeping your game performant.

By combining Continuous collision detection, careful timestep settings, proper collider sizing, and raycasting when needed, you can handle fast-moving objects reliably and avoid tunneling in your games.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar