Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Character controller falling through Box Collider, but very rarely!

Discussion in '2D' started by atmosgames, Oct 18, 2016.

  1. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    Background: Hey there! I'm working on a 2D platformer that utilizes 3D Box Colliders as terrain. Each scene has 5 or so intersecting box colliders that act as terrain. This was the easiest way for me to build out my scene, and actually gives me a high level of control.

    Problem: I'm currently doing beta testing with a testing company, and they have mentioned that, very, very rarely, sometimes the character controller will fall through a box collider into the abyss. I've had this happen on occasion as well, moreso inside the editor than in a standalone build.

    Any ideas as to why this is happening? I assure you, it's not what you think:
    • It's not suddenly becoming a trigger
    • It's not disabling
    • It's not deleting
    • This happens sometimes to my player, but also sometimes to enemies and not the player. It's seemingly randomly.
    It really is just not working. I think it might be a Unity glitch. I've had this happen only in Unity 5.

    What I can say is the box colliders are not ticked as "Static". Should I make all my terrain static? Could this help?

    Or, is the intersection of various box colliders causing a problem?

    Hmmmm.

    Thanks!
    Thomas
     
  2. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    Anyone? Would adding ridgidbodies help?
     
  3. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    Sometime Collision detection set to continuous on a rigidbody2D can help for fast moving objects, also it does depend on where you place the gameobject before the physics engine will pick it up i have found if it was to close to a wall for example and you have a lot of moving objects in that scene the engine might not pick it up in that frame so it could pass though what it hits, that's what happend to me, I could walk though a wall when both had colliders and the player had a rigidbody.

    I think from now on(in new games) and when your in 2D and it's an old style 2D game I'm going to handle the collision myself(raycast) and leave out the rigidbody, this will speed things up I should think.
     
  4. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    Good thoughts. Not really wanting to build using ray casts at this point, as the project is almost complete. What I've found is that if the character controller falls through the box collider, it will always fall through the collider. For example, if the scene loads, and the player falls through the collider, I can move the player back into the scene using transform in the editor, and the player will still fall through. Not sure if that helps.
     
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Double check your depths to make sure the boxes are actually touching. Double check your gameobject layering is consistent and setup correctly with respect to the collision matrix.

    Print out some stuff to the console to find out if collision functions are being hit, what the layers are, etc.
     
  6. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    Thanks for your response jeffrey. They are hitting. 99% of the time, I get a hit. It's only are rare occasions where the hit does not occur.
     
  7. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    run it though the profiler and see if anything is spiking at the point of no collision.
     
  8. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    This is actually the biggest part of the problem. To replicate this would easily require upwards of 20+ hours of testing, and to catch it at just the right time seems extremely difficult. That's what so frustrating. I'm positive this will be a problem with 1% of players, so I have to fix it, however, I can't seem to figure out how to replicate it.

    I'm curious if anyone knows off-hand what could be the problem.
     
  9. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    yeah I know how much a pain in the arse that can be, so how are you doing the collision detection code a snippet might help here.
     
  10. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    There is no detection code. It's a simple character controller and box collider :C
     
  11. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    There must be some sort of hit test, either with ray casting or ontrigger or oncollision?
     
  12. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I realize this is a serious necro, but @atmosgames did you ever figure out what it was? I'm having the same issue. One can play for 10 hours and not see it, or see it twice in 3 minutes. I cannot reproduce it, but I get 2-5 bug reports of it happening to our players every week. And when it happens its catastrophic because the player ends up at the bottom of the ocean.
     
    Haze-Games likes this.
  13. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    182
    Another necro here @djweinbaum and @atmosgames but this is still happening in 2020.1f3, extremely rare, random, and persistent on the object it happens with. There is no clear reason why this would happen.

    Did you ever figure some way out of this, or a way to mitigate it?
    Thanks!
     
  14. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    I abandoned the default character controller and used one from the asset store: https://assetstore.unity.com/packages/templates/systems/easy-character-movement-57985

    I don't expect this to ever get fixed if it's still a problem. It's been a while
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
    Are you guys talking about the 3D physics character controller (the PhysX one) with 3D BoxCollider? I only ask because this post is in the 2D features forums. Sounds like something that should be in the Physics forums.

    I have no idea if this is a reported bug or not. Likely not if it's intermittent and not easily reproducible.
     
    Last edited: Aug 25, 2020
  16. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    In our case, the cause of the bug was rather insane. We were using a asset store asset called herd sim, and very rarely, (more likely when frame rates were low) there was the chance of a sheep suddenly shooting off at such velocity, that its position would pass float.MaxValue. This caused some math operations in the code to throw errors, and somehow affect the call stack down to the character controller. The rest of the game, and indeed the regular physics system as well, would keep going without issue. I never understood why a class throwing errors would affect the character controller in the weird way it did, but fixing those sheep fixed the character controller.
     
  17. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    Is it possible to get the math code that triggers this - it would be awesome if we ever manage to create a true reproducible. We have the same issue, but don't yet of any math overflow or NaN issue.
     
  18. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Unfortunately not. It was a long time ago now, but even at the time I could never get a reliable repro. The bug wasn't happening all from one block. It had something to do with certain collisions. I never identified why the sheep went flying actually, I just destroyed them if they ever went outside certain bounds, and that fixed it (though sheep would go missing occasionally because of this).
     
    PutridEx likes this.