Unity3d Basic Tutorial "(iv): Learn native 2D by making Flappy Bird ...

Source: Internet
Author: User

"Dog planing Learning Net"

Introduction


In the first article"Unity3d Basic Tutorial" for beginners to see the Unity Tutorial (a): Gameobject,compoent,time,input,physicsI've already talked about the relationship between rigid bodies and collisions, and this time we'll go through the example of Flappy Bird to explain the specific applications of rigid bodies and colliding bodies in games. The relevant code can refer toFlappy Bird's source code。
Meet Rigidbody

    • When the mass property of the rigidbody2d is set to 0 o'clock, the mass of the rigid body becomes infinitely large, at which point the rigid body is equal to the static rigid body and is always motionless. But in unity you can't set the quality of a rigidbody2d to 0, so when you want to create a static rigid body, you just need to create a collider instead of creating a rigidbody2d.
    • When we tick the IS kenamatic option, the rigidbody2d is no longer controlled by the physics engine, and we need to control the movement of the rigidbody2d by transform, which is often set in the script.
Note When the gravity scale is set to 0 o'clock, the rigidbody is no longer affected by gravity.
Meet Collider2d
You can add a collider with the following three types of collider in the Add Component option by tapping collider2d in physics2d:
    • boxcollider2d: Box-shaped collider, usually rectangular.
    • CIRCLECOLLIDER2D: Round Collider.
    • POLYGONCOLLIDER2D: Polygon Collider

When we add a collider to a 2D gameobject, this collider automatically chooses the most appropriate size, but you can use the shift+ left mouse button to adjust the bounds of the collider. In a polygon, you can also delete a polygon vertex by CTRL + left mouse button.
Of course, for the same rigid body, we can add multiple collisions for this rigid body to construct more complex collision structures, and you can see the corresponding cases in the official rock demo–2d platformer.
In addition, we can build a more interesting motion by combining the motion of the animation and the rigid body, through the transformation of the transform and through the transformation of the rigidbody does not have to be one of the necessary, about the knowledge of animation can look at my blog:"Unity3d Basic Tutorial" for beginners to see the Unity Tutorial (iii): Through the production of Flappy Bird learn native 2D sprite,animation。
about is Trigger
If the IS Trigger option is checked against a collider, it does not collide with the other collider that is not checked for the is Trigger, and a "Trigger collision" occurs, that is, the message sent at the time of the collision is a Trigger message, not a collision message , and in the script we are going to overload the ontriggerenter instead of overloading the oncollisionenter.
Summary of collision and trigger, which messages are sent when certain attributes are checked separately:

131012159998472.png (553.21 KB, download number: 0)

Download attachments to albums

Uploaded 2 minutes ago



Disclaimer: This document is from the "Dog Planing Learning Network" community, is the Netizen self-published Unity3d study articles, if there is any content violated your relevant interests, please communicate with the official, we will deal with the real-time.

More Highlights:Www.gopedu.com

Unity3d Basic Tutorial "(iv): Learn native 2D by making Flappy Bird ...

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.