- Home /
How to get a 2D polygonal sprite to collide with a Mesh Collider
This is a rather simple question. I have a 2D sprite that really needs the precision of a polygonal hitbox. The 2D, tile-based world around it uses a tile Mesh for efficiency reasons, and thus has a Mesh Collider.
Before, the tiles in the world were each GameObjects with Box Colliders and Rigidbody 2D's, and the ship and the tiles collided just fine. Now that I am using a Mesh Collider, however, they cannot collide. (I have read that this is because one is 2D and one is 3D.) So what should I do to get collisions (preferably with rigidbody physics) between a polygonal ship and a 2D tile mesh?
(Here is the collision mesh I am using.)
Answer by Kiwasi · Oct 17, 2014 at 10:17 PM
To surmise the comments to this question
Meshes are 3D. Polygons are 2D. They exist in separate physics systems and cannot collide.
Polygons are the 2D equivalent to a Mesh
Using a polygon collider is the best option
Also worth noting that you can edit a polygon collider dynamically by using SetPath. This should give you all of the functionality from your mesh.
Answer by Pecek · Jul 18, 2014 at 04:58 PM
The physics engines aren't compatible, use 2d/3d colliders only.
But there is no Polygon Collider 3D. I don't want to use a box collider.
I don't understand the problem, if you want to use 2d physics, then use 2d colliders only, if you want 3d, then use 3d colliders, there is no workaround since they are completely independent from eachother.
The problem is that among the list of colliders in the Physics section, I can only see Box, Sphere, Capsule, $$anonymous$$esh, Wheel, and Terrain. None of these would be precise enough for my needs, unless I used three or four (at least) per sprite. I am looking for a 3D analogue to the Polygon Collider. Otherwise, I am looking for a 2D analogue to the $$anonymous$$esh Collider. Since I need to use both of these, I need to find an equivalent for one of them — but it doesn't seem like those exist.
Polygon collider is the 2d equivalent of the mesh collider. What are you trying to do exactly? Can you post an example image?
Alright... so I have a two-dimensional ship, as seen here, which collides using a Polygon Collider 2D with the bricks also shown there using Rectangle Colliders 2D. Now, however, I have to change the blocks to use a $$anonymous$$esh Collider, as seen here. Since Polygon Colliders and $$anonymous$$esh Colliders do not work together, I need to change something. I tried using other solid colliders such as these; however, this was tedious and played horribly. So what, specifically, should I do to retain the precision of a polygon collider and the speed of a mesh? From your previous posts, I might infer that I can use a mesh collider in place of a polygon collider, but I don't know how to do this. (Is there any documentation?)