"Turn" learn about Rigidbody2d and collider in native 2D by making Flappy Bird

Source: Internet
Author: User

Wang Xuan Yi, Source: http://www.cnblogs.com/neverdie/ Welcome reprint , please also keep this paragraph statement. If you like this article, please click "Recommend". Thank you!


In the first article "Unity3d Basic Tutorial" for beginners See Unity Tutorial (a): Gameobject,compoent,time,input,physics I've already talked about the relationship between rigid bodies and collisions, and this time we're going through flappy. Bird This example to explain the concrete application of rigid body and collision body in game. The relevant code can refer to Flappy Bird source.

Meet Rigidbody

    1. 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.
    2. 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" Unity Tutorial for Beginners (iii): Learn about sprite,animation in native 2D by making Flappy Bird.

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:

Article Directory

"Turn" learn about Rigidbody2d and collider in 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.