• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Starleg2 · May 23, 2018 at 02:20 PM · 2dcollisioncolliderpolygon collider 2drandom gen

How do I use a 2D polygon collider to generate a correct collider for my randomly generated mesh?

Currently I am making a randomly generated 2d tile based game in which a map generator object creates a large number of chunks and then each chunk generates a square of tiles. I have the random generation(or at least part of it) but the idea of collision evades me. The object is a mesh with each tile consisting of 2 triangles but it seems like a polygon collider where I feed it the vertices is the best option since not every tile is its own gameobject and I can't just put box colliders on all of them. My question is how would I use a polygon collider to make the darker regions have collisions while the lighter regions not have collision? alt text

Since polygon colliders have one array of vertices I was wondering how the component determines what the inside of the collider is and how to use a segmented mesh with a polygon collider because at some point my random generation would lead to a chunk being split in two.

unitycollisionissue.png (217.9 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Starleg2 · May 23, 2018 at 02:21 PM 0
Share

Dont' worry about the error, that is just unity freaking out about me editing setting while the game is running

avatar image KeyboardNinja27 Starleg2 · Oct 18, 2018 at 09:41 AM 0
Share

Have you found a solution to your problem? I am currently having a simmilar problem and don't see much in the documentation.

avatar image Starleg2 KeyboardNinja27 · Oct 18, 2018 at 07:11 PM 0
Share

Yeah, I did come to a solution but the answer is on a similar question. https://answers.unity.com/questions/1511762/how-to-make-a-2d-polygon-collider-from-a-mesh.html?childToView=1513286#answer-1513286 should be the link. I included the code as well. The answer involved making an array of all the edges of every tile and removing all edges that overlap using the solid mesh as a starting point thus giving only the edge edges. Then you have to order the edges then finally put the points of the edges into a polygon collider

avatar image tormentoarmagedoom · Oct 18, 2018 at 10:47 AM 0
Share

Good day.

You can make a collider for each tile. If you group all the tiles you need as a child of a parent gameobject, and detect collisions from this parent, all child colliders will act as only 1 collider.

You also have the mesh collider.

You cal aslo have a collider in each tile (so they know what tile type is), and each tile check for collision with objects/player, etc..

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

214 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Efficient generation of 2d polygon collider 0 Answers

Collider2D.IsTouchingLayers() delayed reaction 1 Answer

Platform Effector 2D ignores IsTouchingLayers 0 Answers

No Collision in 2d Scene 0 Answers

Physics2D, Box Collider physics inaccuracy? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges