Search Unity

How to get good collision for round levels

Discussion in '2D' started by conehead, Mar 23, 2016.

  1. conehead

    conehead

    Joined:
    Feb 23, 2014
    Posts:
    12
    Hey guys!

    I am working on my first game and in this game you have to steer your player through the level only with a click/touch. I want to create about 50 levels for this game and I was wondering which is a good way to create the levels.

    As you can see in the image the levels are really curvy and not just primitives.
    What I am doing now is creating the level in Gimp, export as png and import in unity and auto-create a mesh out of it. This seems to be quite an overhead and in addition I am not too happy with the result (collision is too unprecise).

    Is there any hint you can give me on how to create such levels?
    Maybe use an SVG-importer? Or anything else?
    Thanks for your support!
     

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,474
    What do you mean 'not just primitives'? Why not use the EdgeCollider2D?

    The 'precision', as you call it, is simply down to how many edges you create. At some point you need to find an edge resolution that gives you what you need where beyond that it's diminishing returns.
     
  3. conehead

    conehead

    Joined:
    Feb 23, 2014
    Posts:
    12
    Thank you for your reply.
    By "not just primitives" I ment that I do not only need squares and circles. As shown in the image I need to create spirals and stuff like that. Currently I am using a 2d polygon collider. An EdgeCollider2D would surely do the work, but I think that it would be a lot of overhead to create all the levels from scratch and with "smooth/clean" collision.

    I was hoping for a solution with something like splines, so that I can draw splines / arcs and give them a defined width/size.
    Because the whole game is about "colliding with the obstacles" it is quite important for me to get a good collision implemented.
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      90.9 KB
      Views:
      651
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,474
    I'm confused. You say you import an image into unity and auto-create a mesh out of it. So why not then just create an edge collider with a vertex resolution you desire to give you "smooth/clean" collision. I certainly wouldn't use the expensive PolygonCollider2D. At the correct resolution you'll get good collision normals.

    There's nothing available to define a continuous spline surface. To do that, you'd need to implement your own intersection tests.
     
    conehead likes this.
  5. conehead

    conehead

    Joined:
    Feb 23, 2014
    Posts:
    12
    Yes, that is the way I am doing it right now and I was wondering if there are any better solutions ;)
    I used PolygonCollider2D because it was "easy" to use. Just create an Image and import it into the game. Thanks for the hint with not using a PolygonCollider2D. I will definately switch to an EdgeCollider2D now.

    I was just hoping for a solution similar to this one:
    Add an EdgeCollider2D to the image, press a button to auto generate all the vertexes around the image and with a slider change the number of vertexes.
    It was more about using it many many times to different objects, because defining every vertex for every level / obstacle might be very time consuming.

    Thanks again for your help!
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,474
    The PolygonCollider2D can give you a basic outline of a sprite but it is basic and doesn't give you control over the resolution of the outline it creates.

    There's no automation like that for EdgeCollider2D but I'd be surprised if there's nothing on the Asset Store to help you.
     
  7. conehead

    conehead

    Joined:
    Feb 23, 2014
    Posts:
    12
    Most of them are for PolygonCollider2D, but I think I will give it a shot and try what you said.
    Maybe it is not the worst idea to create the EdgeCollider by hand for a couple of levels and see how this works out.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,474
    I was thinking more of using an editor script to generate them from a sprite/texture rather than doing it by hand as that sounds cumbersome. Either analysing the image or allowing you to turn curves into edges.
     
    theANMATOR2b likes this.
  9. vertigostudios

    vertigostudios

    Joined:
    Oct 1, 2012
    Posts:
    101
    Conehead, Im trying to reply to your collaboration post. However, Im unable to respond or send a message.

    If your still looking for a partner I'd like to consider teaming up.

    I'm an artist and you can see a little of my work here :
    www.earlybirdstudios.co.uk and also www.vertigostudios.co.uk

    I'm 42 years of age and reside in the UK.

    If you would like to chat, by all means add me to your skype. My Skype is: vstudios1

    Cheers
    Deano