[Unity3D basic tutorial] Unity tutorial (4) for beginners: Learn about RigidBody2D and Collider2D in Native 2D by making Flappy Bird.

Source: Internet
Author: User

Author: Wang Xuan Yi, source: http://www.cnblogs.com/neverdie/Reprinted, Please keep this statement. If you like this article, click [recommendation ]. Thank you!

Introduction

In the first article [basic Unity3D tutorial], we will show you the Unity tutorial for beginners (1): GameObject, Compoent, Time, Input, and Physics. I have already talked about the relationship between rigid bodies and collisions, this time, we will use the Flappy Bird case to explain the specific application of rigid bodies and collision bodies in the game. For the relevant code, see the source code of Flappy Bird.

Know RigidBody

Note that when Gravity Scale is set to 0, this rigid body is no longer affected by Gravity.

Understanding Collider2D

In the Add Component option, click Add Collider2D in Physics2D to Add a collision tool. The collision tool has the following three types:

  • BoxCollider2D: box-shaped collision tool, generally a rectangle.
  • CircleCollider2D: Circular collision tool.
  • PolygonCollider2D: polygon collision

When we add a Collider for a 2D GameObject, the Collider will automatically select the most appropriate size, but you can use Shift + left mouse button to adjust the border of Collider. You can also use Ctrl + left mouse to delete a polygon vertex.

Of course, for the same rigid body, we can add multiple collision mentions for this rigid body to construct a more complex collision structure. You can see the corresponding examples in the official rock Demo-2D Platformer.

In addition, we can combine animation and rigid body motion to create more interesting motion effects. The transformation through Transform and RigidBody is not necessarily required, for more information about Animation, see my blog: [basic Unity3D tutorial] Unity tutorial for beginners (3): Learn about Sprite and Animation in Native 2D by making Flappy Bird.

About Is Trigger

If the Is Trigger option Is selected for a collision generator, it will not collide with a rigid body with another collision generator that does not check Is Trigger, but will "Trigger Collision", that Is, in this case, the Trigger message instead of the Collision message is sent during the Collision. In the script, we need to reload OnTriggerEnter instead of OnCollisionEnter.

Summarize Collision and Trigger. Which messages will be sent when you select certain attributes:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.