Planets and Gravity

Show off your games, demos and other (playable) creations.
Post Reply
andrew.207
Prole
Posts: 19
Joined: Sat Jun 08, 2013 7:27 am
Location: Melbourne, Australia

Planets and Gravity

Post by andrew.207 »

Hey guys, I saw a cool gif the other day (friend posted it on FB) and decided to write a simple gravity thing that works across multiple planets.
Image

The math is pretty basic, essentially each planetling grabs the nearest planet and has it's valued modified according to direction and gravity. Slightly different to real life, the gravitational pull gets stronger the further away you are. Pretty C++-ish, with the polymorphism and OO.

Look at the source, learn, modify, make the planetlings bounce off the planet, whatever.

It's fairly quick, on my i5 it can handle about 5000 planetlings before it starts to dip in FPS.

License: http://www.wtfpl.net/

Image
Attachments
gravity_OO.love
(2.17 KiB) Downloaded 526 times
Last edited by andrew.207 on Wed Oct 30, 2013 9:21 pm, edited 1 time in total.
http://www.atunnecliffe.com/
Bitcoins? 1LHn9yaErCakYD2iGwCyLungiC7ACxRUW8
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Planets and Gravity

Post by jjmafiae »

WHAT! THIS JUST BLOWN MY MIND! good job!
User avatar
shatterblast
Party member
Posts: 136
Joined: Tue Dec 11, 2012 9:47 pm
Location: Dallas, Texas, USA

Re: Planets and Gravity

Post by shatterblast »

The concept is pretty awesome and sweet. It's like a simulated orbit I guess.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Planets and Gravity

Post by Ranguna259 »

Could you try something for me, I don't have time to peek into you code right know, but could you make two objects, each one with 'gravity', and make them 'moveable' ? I want to see if they start orbiting around each other, if not it's time to start improving your code to a whole new gravitational physics level :P

And if do that you could test your code with the solar system and maybe we could make an atom simulator, that'd be cool
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
andrew.207
Prole
Posts: 19
Joined: Sat Jun 08, 2013 7:27 am
Location: Melbourne, Australia

Re: Planets and Gravity

Post by andrew.207 »

No worries, here you go. It doesn't run off Newton's gravitational constant, it runs off whatever number you type in. I picked 80,000, not sure why.

Seems to work ok, the only awkward part was setting the initial velocities so they didn't just whack into each other.
Attachments
Gravity_OO-atom.love
(2.71 KiB) Downloaded 280 times
http://www.atunnecliffe.com/
Bitcoins? 1LHn9yaErCakYD2iGwCyLungiC7ACxRUW8
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Planets and Gravity

Post by Lafolie »

You might want to check out Gravity Ghost by Erin Robinson and friends.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Planets and Gravity

Post by Ranguna259 »

WOW this is just awesome, I'm definitely going to look into you code this weekend :rofl:

Keep on doing the incredibly awesome work man ^^
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests