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. Dismiss Notice

Rigid Body Not Detecting Collisions

Discussion in 'Scripting' started by Mashimaro7, Jan 27, 2021.

  1. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    723
    I know this seems like a super noob question, but I am absolutely stumped. I have a character I downloaded off the asset store, I have not changed any of the Physics options, but for some reason it's not colliding with anything.

    I have a rigidbody, not set to kinematic, I tried a mesh collider but since that wasn't working, I added a box collider just for testing, it's not detecting collisions, with the ground, it just passes right through anything, I even tried putting a default cube directly underneath it.

    I have no idea what's going on. The collider isn't set to trigger or anything. I made the collider huge just to make sure it was colliding, but no luck. I even tried printing every time "OnTriggerEnter()" is called, but even after passing through 3 objects it wasn't called once.

    Here's a screenshot, if anyone can figure out what I'm doing wrong, maybe I'm just being dumb lol

    upload_2021-1-28_2-17-37.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    If you are moving the character by driving transform.position directly, you can miss physics events. This is because doing so is a "teleport" to the physics system, bypassing it completely.

    If something has a Rigidbody, when you move it you must call the .MovePosition() and .MoveRotation methods on the Rigidbody, or else you are bypassing the physics system.
     
  3. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    723
    Well, I was using transform.position += but, even after disabling that, it still falls right through the ground. Even after disabling my movement script.

    Edit: I just made this project, but is it broken?! I added a plane and a cube with nothing attached but colliders and a rigidbody on the cube, the cube fell through the plane. Wtf? lol
     
    Last edited: Jan 27, 2021
  4. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    723
    Okay, well I found the issue. I imported the Unity 3D Kit and that had apparently broken everything. lol, I'm not using it anyway, so I just made a new project without it.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    To everything there is a reason. Did you look at the physics interaction matrix in the Physics setup? I actually have a copy of that project and looked... note how the default layer is set to not interact with itself. In fact, almost nothing collides with default according to this:

    Screen Shot 2021-01-27 at 2.48.29 PM.png

    To fix, just set the layers on what you're testing to something that IS colliding, preferably following the patterns they set out.
     
    Mashimaro7 likes this.
  6. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    723
    I did have a look at that, but I was being stupid and thought this was layers that were being ignored :p

    Thanks though, I'll fix it. I wonder why they had it set up like this...