Game Development Reference
In-Depth Information
To make sure our player can walk on this, we'll need to give it some collider
properties. With the platform selected in the Hierarchy tab, navigate your cursor
to the menus at the top of the screen and then Component | Physics 2D | Polygon
Collider 2D . You could also go to the inspector with the platform selected, click on
the Add Component button at the bottom, and search for Polygon Collider 2D. Both
ways work, and you are welcome to do as you wish anytime we ask you to add a
component to an object".
With the platform selected in the Scene tab, you'll now see a bunch of green lines
going through the platform. This is by far one of the coolest features of Unity 4.3's
2D support—it automatically creates a polygon collider based on the shape of your
texture (as shown in the following image)! This saves many potential headaches.
Unity determines the shape of the collider based on the alpha of your image, so do
keep that in mind when creating your artwork.
Now, in reality, we could have just used a simple box collider for this platform as
well. However, we would like our enemies to be able to collide realistically with the
platform. On the sides of the platform, it indents in a little. If you try applying a Box
Collider 2D instead of the Polygon Collider 2D, which you can see in the following
image, you'll see that it goes straight down at the sides:
 
Search WWH ::




Custom Search