Advertisement

Need guidance in making 2D game involving gravity

Started by March 08, 2020 06:38 PM
2 comments, last by SyncViews 4 years, 8 months ago

Hello everyone, I'm about to make a hyper-casual game for mobile devices, haven't decided yet what engine to use for native app (superficial research says it should be unity) but current prototype is built using pixi.js since that's a tool i'm most familiar with. Basic gameplay is revolving around nodes (let's say planets) and a ball that is rotating around a node, can detach from it, go to free fly and attach to another node if it's close enough (like a small space object that get's into gravity field of another large object). Right now i'm not using any physics engines but would like to simulate some gravity behavior in a more realistic manner but leave some other aspects in a simplified manner. Can you provide any guides, books or anything else that would help to dive into the problem of realistic and not so gravity imitation in games? Thanks in advance!

P.S. video for ref https://imgur.com/a/gwslwc7

I thought overshoot was the fun part. Realistic computation ends with the collision. Do it like they did for the Apollo moon landing:

https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

Advertisement

I am kinda confused as to how far you got, and at what stage you got stuck.

You can apply acceleration towards an objects centre of mass. The general equation is `F = G * (mass1 * mass2) / distance^2`. Where mass is kg, distance metres and G the gravitational constant (6.674 * 10^-11).

In most cases you will have one huge object (e.g. a planet) and a small one (e.g. a ship), so you can simplify to `acceleration = (G * large_object_mass) / distance^2`.

Now, an interesting feature is that in most scenarios, because of how quickly the gravitational force decreases with distance, there will often only be one significant force acting on a given object, so your “attach to another node if it's close enough” is simply the point where you transition from one to another, https://en.wikipedia.org/wiki/Patched_conic_approximation.

In fact this is how Kerbal Space Program works, there is only ever a single force of gravity, and the transition is the “sphere of influence” or “SOI” change (https://wiki.kerbalspaceprogram.com/wiki/Sphere_of_influence). It is also why a few orbits are not possible, such as Lagrange points (https://en.wikipedia.org/wiki/Lagrangian_point) as multiple gravitational forces are needed.

One problem I know KSP had is with floating point accuracy, but that depends on how big a scale you are planning to work at, and means the actually simulation sees the universe move around the player, rather than the origin point always being say the centre of the sun.

This topic is closed to new replies.

Advertisement