Jump to content

Create an Angry birds space like gravity


DWboutin
 Share

Recommended Posts

Hi!

I want to create a planet like gravity like Angry Birds space, or look a like. But i don't know how to start with this. What i must know? Is there some articles out there who explain it?

How can i make a plateformer on a round planet without my character get stuck in the side?

Thank you for your help!

Note: its the same post as http://www.html5gamedevs.com/topic/2599-create-round-planet-gravity-like-angry-birds-space/, i wanted to move it in this thread but i don't know why.

Link to comment
Share on other sites

disclamer: I didn't yet try to make this kind of physics, but this is how I would try to achieve that.

DWboutin, I think that you just have to compute vector from your object origin to planet origin and cast gravity force on it. Now it should be easy to get velocity of an object.

Link to comment
Share on other sites

I'd suggest you start by looking at some tutorial on creating particle systems. Most particle systems include the attractors and deflectors needed to simulate planet-like gravity fast enough for use in a game.

 

I'll check it for sure ^^

 

 

disclamer: I didn't yet try to make this kind of physics, but this is how I would try to achieve that.

DWboutin, I think that you just have to compute vector from your object origin to planet origin and cast gravity force on it. Now it should be easy to get velocity of an object.

 

What you mean by compute vector (sorry, i'm french canadian, maybe i don't recognize the words)

 

 

i don't know if you are familiar with box2d or not, but maybe this tutorial could help, it does exactly what you need, the only problem that you may face is Box2D & ActionScript 

http://www.emanueleferonato.com/2012/03/28/simulate-radial-gravity-also-know-as-planet-gravity-with-box2d-as-seen-on-angry-birds-space/

 

Thank you, i don't know Box2D, but the code is readable. I'll try it!

Link to comment
Share on other sites

  • 4 months later...

Just to add to this, the key concept you'll be working with is Newton's law of universal gravitation. Basically, this just says that the gravitational force between 2 objects is directly proportional to the product of the masses of the two objects, and inversely proportional to the square between them.

 

If you do a search, you'll encounter a formula for this concept, but for your game, you probably won't be needing the actual constants used in real life - instead, you'll have to figure out the "gravitational constant" that feels right for your game.

 

The actual formula is F=G*m1*m2/(r*r), but since you'll probably be needing just the acceleration, instead you'll just need to compute something like K*m/(r*r), where K is the constant you've figured out for your game, m is the mass of the i'th planet (you'll probably have more than 1 planet in your game), and r is the distance between the planet and the projectile whose trajectory you are trying to compute.

 

Here's some (untested) code that should give you an idea of how to do it:

var GRAVITATIONAL_CONSTANT = /* this depends on what feels right for your game */;for each (var projectile in projectiles) {    for (var planet in planets) {        var dx = planet.x - projectile.x;        var dy = planet.y - projectile.y;        var distanceSquared = dx * dx + dy * dy;        var distance = Math.sqrt(distanceSquared);        var acceleration = GRAVITATIONAL_CONSTANT * planet.mass / distanceSquared;        projectile.velocityX += acceleration * (dx / distance);        projectile.velocityY += acceleration * (dy / distance);    }    projectile.x += projectile.velocityX;    projectile.y += projectile.velocityY;}

You might still be able to optimize the above code by combining computations further, and of course you'll have to consider collisions, and maybe even use a different integrator such as RK4, but hopefully this should serve as a solid starting point.

 

Of course, remember that it's your game, so you don't strictly have to follow the laws of physics, but it can serve as a good starting point, so feel free to bend the rules.

 

Of course, there's also the option of using a physics engine such as Box2D - the principles illustrated here should still hold, you'll probably be applying forces just like how it's done above.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...