Make 2D Collision for Maze (Sprite) in Unity

As1anzAce
3 min readAug 18, 2020

Hello mellow fellows, me here to share a few steps for creating the collision of maze.

My 1st Unity Beginner’s Tut. Just 4 sharing…

You will follow me thru these things:

  1. Generating Maze
  2. Edit and export to Unity
  3. Use Sprite Editor in Unity to apply Custom Physics Shape
  4. (Optional) Edit more Outline for more accuracy
  5. Put the sprite into the scene
  6. Add Component — Polygon Collider 2D
  7. Testing for finishing

Generating Maze

The maze can be imported or generated by the program, both online and offline. But, me will use amaze (offline program) to generate a simple maze. We can also use online generator at mazegenerator.net . The generated maze can be saved as .png or etc.

The output is an image file..

Edit and export to Unity

Once we get our favored maze. We will edit that maze a lil bit in the image editor.

Reason: We just “love” the walls!

Don’t forget…! Export that edited image file (maze) to your Unity project.

Use Sprite Editor in Unity to apply Custom Physics Shape

Folders n Files…

i) Open Unity

ii) Try locate our maze file in the Unity project.

iii) Click maze

iv) Then, click Sprite Editor

v) Sprite Editor tab will popup!

vi) Choose Custom Physics Shape

vii) Set Outline Tolerance to 1 , and click Generate

viii) Click Apply

Halfway through!

(Optional) Edit more Outline for more accuracy

You may skip this step if satisfied enough with the previous result..

This example is done for more detailed work (better collider accuracy).

Put the sprite into the scene

Just drag maze into the scene.

Automatically, new Game Object named “maze” is created!

Add Component — Polygon Collider 2D

Me put polygon collider to maze.

Polygon Collider 2D size = Outline (Custom Physics Shape) size

Testing for finishing

We can put the moving character in the scene, together with the completed maze.

Test collision with player.

Congrätz!! We have our playable Maze.

In a nutshell, we can create the maze collision with the easier way — Polygon Collider 2D. EXTRA: We can also create collision for the maze by using a lot of Box collider 2D. Hopefully, this tutorial could help your great works. Thank you so much for reading and me very appreciate your precious time. May God bless your works.

--

--

As1anzAce

AA. Me is just an ordinary student. Gladly can share my knowledge and ideas. #000fff