- Home /
Can I make a hole in a mesh collider?
I'm building a cave system for my game and there are separate cave 'houses' that go inside it but I want them to protrude out through it like you're walking into a dug out area in the wall. I'm using a script to set the render queue that makes it so you can't see the cave walls that come through but is there a way to make it so you can pass through part of a collider while the rest of it still works?
Answer by Sergio7888 · Oct 13, 2016 at 04:56 PM
You cant make a hole in a collider, you can use multiple child objects with small colliders, or depending the case change the Collision Matrix.
Okay, I guess I'll just change the mesh since it's too complicated to use a series of built in colliders for. The Collision $$anonymous$$atrix seems interesting for other applications though, I hadn't read about that before. Thanks.
Technically speaking, you can make a hole in a mesh collider by regenerating the shared mesh with certain modifications. However, it would take a lot of work and wouldn't necessarily be practical.
Answer by OusedGames · Oct 15, 2016 at 04:41 PM
I do not know if I undestand your question but I will try to help:
When player collides with the wall
You Disable the wall collider and when the player goes through, re enable it again;
void OnColisionEnter(Collision col) {
if (col.gameObject.tag == "Wall") {
col.gameObject.GetComponent<MeshCollider>().enabled = false;
}
}
Then use a Coroutine or float var on update to reactivate the collider;
Hope it Works @sporkflips
I guess this could work so that if the player is within a certain area the mesh collider would be disabled, but I suppose it was probably easier to just fix the mesh so that it wouldn't be in the way to begin with. I would think this would also only work if there are no other game objects that would fall through the mesh while it's disabled. This is interesting to keep in $$anonymous$$d though, could it be applied to a Terrain object?
Yes, it could be problematic if it's important for the collider to continue to work with other objects. A similar approach, which might get around this problem, would be to temporarily change the layer of the player gameobject to one which doesn't interact with the layer of the collider (as defined in the physics settings). This might also be problematic of course, but differently so.
Seems to me that the other approach (ie not having a collider in the place where you don't want collisions) is likely to be better in most situations.