??
Physics in Unity:
With a real physical behavior, your game object must be affected by collisions, gravity, and various other forces. To emulate this physical feature is one of the main features provided by Unity's physical engine (although many large projects are not used by it).
Gravity:
Gravity, bringing together the power of all matter. matter consists of any tangible thing. Gravity is a linear proportional relationship. So, there are a lot of problems, gravitational force on the things around the flight of centripetal force. Quality is how we measure the amount of material things. The bigger thing is the greater the mass, the more gravity it produces. As we walk on the surface of the Earth. But because the earth is much more than us, and the gravity of the earth can make us fall on the ground, besides depending on the mass used, gravity also depends on how far your things are. This is why we are on the surface of the earth and not on the surface of the sun, in your game to achieve the impact of the Earth's gravity.
Demonstration projects:
Open unity and go to File > New Project. Give the project a name and choose 2D. Create a scene with the main camera main cameras, the planetary sprite, the bird sprite and the canvas containing the text, as shown below:
Pictures can be downloaded from the Internet and set as follows:
Go to Gameobject > UI > Text and you can fill in your content. Here, I use the text content in the game view as "Press Space". Now, rotate the bird near the planet, write a C # script as shown, and apply it to your bird.
Bird.cs:
Using unityengine;using System.collections;public class bird:monobehaviour{public Transform planet;private float Forceamountforrotation = 10;private Vector3 directionofplanetfrombird; private bool Allowforce; void Start () { directionofplanetfrombird = Vector3.zero; } void Update () { allowforce = false; if (Input.getkey (keycode.space)) Allowforce = true; Directionofplanetfrombird = transform.position-planet.position; Transform.right = Vector3.cross (Directionofplanetfrombird, Vector3.forward);} void Fixedupdate () {if (Allowforce) rigidbody2d.addforce (transform.right * forceamountforrotation);}}
Add the gravitational pull of the bird to the center of the planet, write a C # script as shown below and apply it to your planet.
Using unityengine;using system.collections;public class planet:monobehaviour{public Transform bird;private float Gravitationalforce = 5; Private Vector3 directionofbirdfromplanet;void Start () {directionofbirdfromplanet = Vector3.zero;} void Fixedupdate () {directionofbirdfromplanet = (transform.position-bird.position). normalized; Bird.rigidbody2D.AddForce (Directionofbirdfromplanet*gravitationalforce);}}
This play scene, and then run will see the effect Ah!
The gravitational effect of a planet like Angry Birds