Search code examples
c#unity-game-enginecollision-detectiongame-physicsgame-development

Unity cannot detect fast collisions


In my simple 3D Unity Game, some gates are spawning on the players way and some of them gives more point and make the game faster so it becomes harder to avoid closed gates but at some point when the game becomes really fast unity cannot detect the collision and player pass through the closed doors but nothing happens or player pass through plus3 gates but score doesn't change.

Here is my Rigidbody settings I also tried it with trigger but nothing changed.

 public void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("plus3"))
        {


            score += 3;

            Destroy(collision.gameObject);

            speed += 4f;


        }
}

Solution

  • Assuming that you are using the Rigodbody API and not simply teleporting the object along the path, you can decrease the physics time step under Edit > Project Settings > Time > Fixed Timestep, so collisions are checked more often. It comes at the price of performance, so be mindful when choosing a value.