Welcome to Unity Learning,Unity training ,UnityEnterprise TrainingEducation Area, there are manyu3d Resources,u3d Training Video,u3d Tutorials,U3d Frequently Asked questions,u3d Project Source code, the "Dog Planing Learning Network" Unity's Ultimate Academy, dedicated to building the industry unity3d Training , learning the first brand.
This time we will explain the concrete application of the rigid body and the collision body in the game through the example of Flappy Bird. The relevant code can refer to Flappy Bird source.
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.
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:
For more information, please visit the "Dog Planing Learning Network" Unity Ultimate Academy Http://edu.gopedu.com
Statement: This document comes from the "Dog Planing Learning Network" Community-unity Extreme College, is a self-published Unity3d study articles, if anything violates your relevant interests, please communicate with the official, we will deal with the real-time.
Learn about Rigidbody2d and collider2d in native 2D by making Flappy Bird