Page 3 of 3

Re: Gravitonik

Posted: Sun Jan 17, 2010 11:44 pm
by nevon
What I like most about this game is the fact that you can run around a planet so fast that you'll just fly off into infinity.

Seriously though, great work! It's one of the best looking games I've seen made with Löve. The menu screen is especially well made.

Re: Gravitonik

Posted: Mon Jan 18, 2010 1:01 am
by TechnoCat
nevon wrote:What I like most about this game is the fact that you can run around a planet so fast that you'll just fly off into infinity.
Hahahaha, I just tried that, it was awesome. :megagrin:

Re: Gravitonik

Posted: Wed Jan 27, 2010 3:54 pm
by nevon
I've been looking through your code, trying to find the part that deals with the planets' gravity and how it affects the players direction and velocity, but I haven't been able to find it (the code is quite sparsely commented). If you would be so kind as to explain it to me, or at least tell me which part that is relevant, that would be great!

I'm asking because I'm trying to implement something with physics similar to that of a pool game, but with certain static bodies that attract the balls if they are close enough - very much like your planets.

Re: Gravitonik

Posted: Thu Jan 28, 2010 8:15 am
by middlerun
No problem. The gravity is just a straightforward implementation of Newton's Law of Universal Gravitation. Here's the relevant bits, I trimmed out some other stuff:

Code: Select all

force_x = 0 -- Start with zero force
force_y = 0
for i = 1, numplanets, 1 do -- Iterate through each planet and calculate the force with which it attracts the spaceman
  dist = math.sqrt((p_pos_x[i] - sm_pos_x)^2 + (p_pos_y[i] - sm_pos_y)^2) -- This line calculates the distance between the spaceman and the planet (Pythagoras' theorem)

...Some other stuff...

  if dist ~= 0 then -- This is to avoid potential divide by zero errors, because at one point the code was buggy and it was possible to fall under the planet's surface so the distance could be zero
    force = (G * p_mass[i] * sm_mass) / dist^2 -- Calculate gravitational force using Newton's Law. G is just a constant I tweaked until it seemed good
    dir_x = (p_pos_x[i] - sm_pos_x) / dist -- Calculate the direction the force is pulling
    dir_y = (p_pos_y[i] - sm_pos_y) / dist
    force_x = force_x + force * dir_x - 0.0002 * sm_v_x -- Calculate the gravitational force due to this planet as separate x and y components and add it to the running total
    force_y = force_y + force * dir_y - 0.0002 * sm_v_y
  end
end

...Some other stuff...

sm_acc_x = sm_mass * force_x -- Newton's 2nd law, though I just realised I wrote it wrong. It should be sm_acc_x = force_x / sm_mass, not that it matters that much since the spaceman's mass doesn't change and the units of mass and force are arbitrary
sm_acc_y = sm_mass * force_y
sm_v_x = sm_v_x + sm_acc_x -- Update velocity
sm_v_y = sm_v_y + sm_acc_y
sm_pos_x = sm_pos_x + sm_v_x * dt -- Update position
sm_pos_y = sm_pos_y + sm_v_y * dt
The variables beginning with p_ are for planets, and the ones beginning with sm_ are for the spaceman.

As you can see the x and y components for pretty much everything are calculated separately. I'm not 100% sure but I think I could even run the Law of Gravitation separately for x and y [EDIT: Actually I'm pretty sure that wouldn't work]. I guess I should add all these comments to the code, I'm terrible about comments.

In other news, the game is coming along gradually but nicely. I've got about 11 levels done now, plus new planet styles, and lots of bugfixes and small cosmetic changes. Though it will still be at least a week to the final release, making levels takes longer than I expected.

Re: Gravitonik

Posted: Thu Jan 28, 2010 10:52 am
by bartbes
About your guessed G, in real life it's 6.6726*10^-11 Nm²/kg². Just wanted to tell you.
And the formula was as I expected: F = G * M * m / R^2 (M being the mass of the large object, m of the small, although it doesn't really matter which is which.)

Re: Gravitonik

Posted: Thu Jan 28, 2010 1:19 pm
by middlerun
Yeah, I know. But if I'd used that I would have had to use ridiculously large values for the planet masses or the spaceman's mass. So I lie. :megagrin:

Re: Gravitonik

Posted: Thu Jan 28, 2010 4:49 pm
by Robin
bartbes wrote:About your guessed G, in real life it's 6.6726*10^-11 Nm²/kg². Just wanted to tell you.
And the formula was as I expected: F = G * M * m / R^2 (M being the mass of the large object, m of the small, although it doesn't really matter which is which.)
You know, funny you bring this up.

We were explained exactly this formula on school today. Of course, I knew it already. ;)

Re: Gravitonik

Posted: Fri Jan 29, 2010 1:22 am
by Fourex
Great game! It's the only game I've seen in Löve that's close to being finished. You've got a great concept going! There's just one thing; the controls for rotating the space man feel very sensitive. Maybe put a little rotational friction on him? Right now it's hard to point him in the right direction quickly, without over-rotating. Oh, and it was very easy to figure out the goal, and the controls.

Re: Gravitonik

Posted: Tue Mar 09, 2010 10:38 am
by middlerun
Hi everyone, I just thought I should let everyone know what's going on with Gravitonik, since I kind of disappeared after stating the game would be finished in a matter of weeks. Unfortunately life has interfered as it so often does, I got a job and now I'm back at uni and don't have a lot of time to spend working on levels, which is a shame because I'm only a few levels away from finishing the game. I plan on finishing it eventually, but in the meantime here's what I've got so far:

Gravitonik v0.1.7

The levels without names are just placeholders, so is the "random level generator". And the last level is nowhere near finished. Apart from that most of it is done.

Re: Gravitonik

Posted: Thu Mar 11, 2010 5:21 am
by steventrouble
Rofl, the artwork and performance is amazing, but there's no limit to how fast I can run on a planet... I kept running around until my sprite became a single sprite again, and I jumped about 18 minutes ago, and I'm still flying outward. :rofl: