Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Raycast against concave mesh doesn't work

Discussion in 'Physics' started by kamac, Dec 18, 2015.

  1. kamac

    kamac

    Joined:
    Mar 21, 2014
    Posts:
    13
    Hey there.

    I've got a mesh that requires concave collider, so I've set one up. The thing is, raycasts don't work against it. It behaves very weirdly, and it's visible when for example trying to place an object on the concave mesh in the editor. Sometimes it will detect where the object should be placed (while dragging), sometimes it will just place it in the air. My mesh doesn't have a rigidbody component, it's just a static island.

    Is this a known thing? I'm using Unity 5.2.3f1.

    I've tried splitting my mesh up into smaller chunks and setting those separate parts as concave colliders, but that didn't help.

    I'll add that CharacterController works fine with the concave collider. It's just that the raycasts don't work.

    EDIT
    Checked, it doesn't work on Unity 5.3.1 either.

    EDIT2
    Here's the mesh: https://dl.dropbox.com/s/hvf0c544ugz9skf/SummerIsland.fbx?dl=1
    Just try to add a mesh collider to it and place another object on it after that. You'll see that raycasts don't hit it / hit it in very weird positions. Then try setting it to a convex mesh, and the ray casts will work.

    EDIT3
    Apparently saving the object as .3ds and then as .fbx again solves the issue. The hell?
     
    Last edited: Dec 18, 2015
  2. Tion-Gaming

    Tion-Gaming

    Joined:
    Jan 30, 2015
    Posts:
    28
    I am very sorry to necro this old post, but I just ran into a similar problem as was pulling my hair out to solve it. I was using a 2d mesh to raycast against to know what footstep sounds to play in specific areas, and one day i noticed that the footsteps werent working as I expected, it was always playing defaults. I tried everything I could think of until I was looking into converting the mesh into concave and stopped to consider why it is called concave in the first place. I started thinking about the triangles then boom, it hit me, unity only does raycast against the outward facing side of polygons unless you explicitly tell it otherwise. My problem was I had originally designed the colliders to be above the player, but reworked the system to make it below the player, however I never changed what side the "face" was (its always been a collider, not an actual object with a mesh so I would never know). I flipped it around and, sure enough, everything was back to working and I feel like a dunce.

    For anyone who is running into a problem like this, Make sure you have the faces correctly set up. Id guess when op saved the object as .3ds and then to fbx, somewhere in the process the faces got recalculated which caused to work as expected.