Search Unity

Unity5f4: Bug in CharacterController.

Discussion in 'Physics' started by krisu, Mar 14, 2015.

  1. krisu

    krisu

    Joined:
    Jul 10, 2013
    Posts:
    40
    Hello
    I have problem with CharacterController in Unity5f4.
    Its look like CharacterController not always detect collisions.
    Sometimes just randomly ignore some BoxColliders etc and then CharacterController
    just falling through collider.
    Everytime when run a game sometimes some colliders is ignored, sometimes is all ok.

    I prepare little code to reproduce this problem:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Test : MonoBehaviour
    6. {
    7.     public        GameObject            toCharacter;            // any prefab with CharacterController
    8.     public        GameObject            toCreate;                // any prefab with BoxCollider
    9.     public        int                    amount = 250;            // how many cubes to create. more == greater chance of collider fail
    10.  
    11.     private        bool                onlyOneTime;
    12.     private        CharacterController    cc;
    13.  
    14.     int TestCollision()
    15.     {
    16.         // now we testing boxcolliders floor...
    17.         // sometimes charactercontroller.Move() ignore some boxcolliders
    18.         int c = 0;
    19.         for(int x=0;x<amount;x++)
    20.             for(int y=0;y<amount;y++)
    21.             {
    22.                 cc.transform.position = new Vector3(x*2,5,y*2);
    23.                 CollisionFlags cf = cc.Move(Vector3.down * 100);
    24.                 if((cf & CollisionFlags.Below) != 0) c++;
    25.             }
    26.       return c;
    27.     }
    28.  
    29.     void Start ()
    30.     {
    31.         // create charactercontroller for testing
    32.         GameObject gp = (GameObject)Instantiate(toCharacter);
    33.         cc = gp.GetComponent<CharacterController>();
    34.  
    35.         // create boxcolliders as floor for charactercontroller
    36.         for(int x=0;x<amount;x++)
    37.             for(int y=0;y<amount;y++)
    38.                 Instantiate(toCreate,new Vector3(x*2,0,y*2),Quaternion.identity);
    39.     }
    40.    
    41.     void Update ()
    42.     {
    43.         if(onlyOneTime == false)
    44.         {
    45.             int x = TestCollision();
    46.             Debug.Log( x + " boxes collided, but should " + (amount*amount) + " collided." );
    47.             onlyOneTime = true;
    48.         }
    49.     }
    50. }
    51.  
    everytime when i run i have different results in Debug.Log:

    Run nr.1: (some colliders fail)
    62454 boxes collided, but should 62500 collided.
    Run nr.2: (sometimes is ok)
    62500 boxes collided, but should 62500 collided.
    Run nr.3: (some colliders fail)
    62488 boxes collided, but should 62500 collided.
    Run nr.4: (some colliders fail)
    62470 boxes collided, but should 62500 collided.
    Run nr.5: (again is all ok)
    62500 boxes collided, but should 62500 collided.
    Run nr.6: (some colliders fail)
    62458 boxes collided, but should 62500 collided.
    Run nr.7: (again ok)
    62500 boxes collided, but should 62500 collided.
    Run nr.8: (fail)
    62464 boxes collided, but should 62500 collided.
    Run nr.9: (one collider fail)
    62499 boxes collided, but should 62500 collided.
    Run nr.10: (now is ok)
    62500 boxes collided, but should 62500 collided.

    also i prepare unitypackage with test.scene.
     

    Attached Files:

  2. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    i tried smaller number of colliders like 5K i didn't see any collisions missed ..
    in my opinion.. i don't think there is a game need that sort of huge of check of 62k+ in one frame.
     
  3. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    Hello. I am expiriencing same issue, but it occurs randomly when I hit Play button and my scene is using not more than 50 colliders, maybe less.
    Bump, please!
     
  4. Daniel-Strayer

    Daniel-Strayer

    Joined:
    Apr 16, 2013
    Posts:
    68