Search Unity

Walking through walls

Discussion in 'Physics' started by ItzChris92, Sep 16, 2018.

  1. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    264
    Hi, I've been playing around with cave generation, and using this:

    https://github.com/AK-Saigyouji/Procedural-Cave-Generator

    The problem i'm having is my character is able to move through walls. The walls themselves have a mesh collider, whilst my player has a kinematic RB, and a capsule collider (I've tried this capsule collider on both my player object, and a child of with the same results).

    I've searched high and low, but haven't been able to come up with a solution. I'm hoping someone can offer a bit of advice as there seem to be lots of cases where this issue has remained unsolved!

    EDIT: Also, just to clarify, I move my player using rb.MovePosition rather than transform.translate
     
  2. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    Review the Collider documentation found here:
    https://docs.unity3d.com/Manual/CollidersOverview.html

    You may need to review mesh colliders as well.
    https://docs.unity3d.com/Manual/class-MeshCollider.html

    If you look at the matrix at the bottom of the colliders overview, you will see your problem.
    You have a Kinematic Rb Collider colliding with a mesh collider(non Rb I assume).
    This means no collision is being detected.
    Reveiw the collider matrix and decide what you need to do to fix it.
    You should be able to use non-kinematic Rb on your player but I don't know how your player is setup.

    Also, I did not look at the cave generator but it really is irrelevant and you just need to follow the collision matrix.
    Another thing, is usually good practice to avoid mesh colliders if possible.
    The reason being is because they are expensive and usually do odd things like you have found.

    Here is a recent post explaning the cost of mesh colliders
    https://gamedev.stackexchange.com/q...-how-is-a-mesh-collider-performance-expensive