My Camera is colliding with Mesh Colliders for meshes that I generate at runtime despite the Camera object not having any colliders or rigid body, and being assigned to a Layer that shouldn’t collide with anything in both the 2D and 3D Collision Matrix, and being assigned to the Exclusion Layers on the collider.
Example:
When camera moves over the generated mesh, the physics will automatically push the camera around the perimeter of the object instead of moving through it. Meanwhile other game objects (such as characters) can freely pass through the generated mesh and are unaffected.
Here’s the steps that occur:
- Script creates a mesh
- Assigns the mesh to the object’s mesh collider
- Assigns the Camera’s layer to the Exclusion layer
Here’s the code that does this:
gameObject.layer = LayerMask.NameToLayer("Terrain");
MeshCollider collider = GetComponent<MeshCollider>();
collider.sharedMesh = SurfaceMesh;
collider.excludeLayers = LayerMask.GetMask("Camera");
Camera Object is just an Empty with scripts attached
It does have children Empties for the Hinge and Arm but they’ve also been assigned to the Camera Layer and their only Components are a Transform
The generated mesh is just a basic 4 vertex plane
3D Collision Matrix
2D Collision Matrix
Any ideas what I’m doing wrong?