# 2D Platformer - Environment Collision

Hello all, I’ve been researching this 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 within 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 this all makes sense, please let me know if more explanation is needed.

• Create a alpha channel collision map.
• import the collision map asset.
• Use Unity’s built in collider generator(see space ship collider in 1.
• Done!

This should work really well because all edges are horizontal or vertical.

My recommendation is not to use the unity collision system at all in this 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.