Sponsored By

Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs.

Equation for Space Gravity like Angry Birds Space

The Maths behind the gravity effect of planets in angry birds space is far different from the actual equation of gravity of a real planet.

Vijay Kartick Prem Kumar, Blogger

October 19, 2013

1 Min Read

The Eluding Gravity Equation

When i was programming my first game "Tank in Space" ( which is about manuvering a tank in space like in "A-Team"), i wanted my tank to orbit the Planet. I searched many sites to see how it was implemented in Angry Birds Space, but none could provide a clear picture. After several experiments i succeeded in finding the equation which makes any object revolve around a planet irrespective of speed of arrival inside gravity field.

You can check out my implementation in my game

https://play.google.com/store/apps/details?id=com.jaykalabs.atank1free

The Implementation

 

 

The normal equation of Gravity is

F = G frac{m_1 m_2}{r^2}

If you implement this equation as your planet's gravity equation your object will mostly fly away from field.

Instead of using this equation you can simply accelerate the object towards center of planet by a constant value.

In Unity it is implemented as rigidbody.addforce(ObjToCentervector,Forcemode.acceleration)

This implementation gave rise to another problem. Acceleration increases velocity exponentially which will make the game very difficult to control.

So instead of using Forcemode.acceleration use Forcemode.VelocityChange which makes your game more controllable. Besides you can change the Drag of the rigidbody to have even more control. I used a value of 0.1 for drag which made the tank go upto the edge of field before orbitting. Increase the drag value if youu want the object to orbit earlier. This will however make the object lose velocity soon and spiral into the planet early.

Hope this article helped you.. Try my game https://play.google.com/store/apps/details?id=com.jaykalabs.atank1free

 

 

Read more about:

Featured Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like