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:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
public GameObject toCharacter; // any prefab with CharacterController
public GameObject toCreate; // any prefab with BoxCollider
public int amount = 250; // how many cubes to create. more == greater chance of collider fail
private bool onlyOneTime;
private CharacterController cc;
int TestCollision()
{
// now we testing boxcolliders floor...
// sometimes charactercontroller.Move() ignore some boxcolliders
int c = 0;
for(int x=0;x<amount;x++)
for(int y=0;y<amount;y++)
{
cc.transform.position = new Vector3(x*2,5,y*2);
CollisionFlags cf = cc.Move(Vector3.down * 100);
if((cf & CollisionFlags.Below) != 0) c++;
}
return c;
}
void Start ()
{
// create charactercontroller for testing
GameObject gp = (GameObject)Instantiate(toCharacter);
cc = gp.GetComponent<CharacterController>();
// create boxcolliders as floor for charactercontroller
for(int x=0;x<amount;x++)
for(int y=0;y<amount;y++)
Instantiate(toCreate,new Vector3(x*2,0,y*2),Quaternion.identity);
}
void Update ()
{
if(onlyOneTime == false)
{
int x = TestCollision();
Debug.Log( x + " boxes collided, but should " + (amount*amount) + " collided." );
onlyOneTime = true;
}
}
}
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.
2019465–130653–boxcollider.unitypackage (12.1 KB)