• 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
1
Question by sgttravers · Nov 20, 2012 at 04:03 PM · 2dcollisionplatformerpixel

2D Platformer - Environment Collision

Hello all, I've been researc$$anonymous$$ng t$$anonymous$$s question for quite some time now and have never really been able to nail down an answer, so I felt it was time to ask it here.

I would like to create levels/environments, if you will, similar to the game Small Worlds by David Shute; see the images below to get a better idea of what I'm referring to.

Now I'm not interested in copying the game in any way, my question has to do with how to create a pixel perfect terrain in 2D wit$$anonymous$$n Unity like in Small Worlds, specifically how to create the collision bounds for the level. Creating the art (all the pieces and their counterparts) is very easy in a program like Photoshop or Gimp, and placing them in unity on 2 triangle planes and arranging them to make up the level is trivial, but how do I then create all the collisions for the environment. Do I really have to take collision boxes and place them on each square around the environment by hand? You'll notice that some of the environment in Small Worlds has single pixels that the character can collide with and needs to jump over, so would that have it's own collision box and so on, or is there a better way?

Hope t$$anonymous$$s all makes sense, please let me know if more explanation is needed.

alt text

alt text

small_worlds_screenshot_1.jpg (42.8 kB)
small_worlds_screenshot_2.jpg (85.2 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Spinnernicholas · Nov 26, 2013 at 10:52 PM

  • Create a alpha channel collision map.

  • import the collision map asset.

  • Use Unity's built in collider generator(see space s$$anonymous$$p collider in video.

  • Done!

T$$anonymous$$s should work really well because all edges are horizontal or vertical.

Comment
Add comment · Share
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
0

Answer by MadDave · Nov 20, 2012 at 04:22 PM

My recommendation is not to use the unity collision system at all in t$$anonymous$$s case. Instead, fill the whole level (image) into an array. When you move the character, check the array whether a particular position is blocked or not. The player position may still be a fractional number.

Alternative solution: I you really want to use Unity collision boxes, make a tool that creates the boxes for you. A "greedy" algorithm may work here: start with one pixel and enlarge the box row by row and column by column. Start a new box when you have to. Pretty much the same process you would do manually.

Comment
Add comment · Show 2 · Share
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 sgttravers · Nov 20, 2012 at 04:46 PM 0
Share

Thank you for your input. I like the sound of your first idea; however, I've never tackled anything like that before. Could you give me an idea maybe using pseudo code on how I might get started with this. Moreover, say I have enemies within the level, in that case should I handle collisions between player and enemies (or any other dynamic objects) with Unity's collision system, or could I accomplish collision detection with your recommended method as well? Thanks again.

avatar image Spinnernicholas · Dec 03, 2013 at 12:40 AM 0
Share

Unity can do this automatically already using the alpha channel of the texture. After Unity finishes, you can tweak and fine tune the collider.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Pushing against Edge Collider wall stops player from falling 0 Answers

Why does my OnCollisionEnter2D not work? 3 Answers

Pixel Perfect Collision 2d 0 Answers

jumping through and on a platforms(2d) 1 Answer

Collision not working for 2d platformer 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges