Physics gravity conundrum

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Design for game, asset for game, game kit, UI design, completed design for game, mobile game, Gravity Shift
  • I'm wondering if anyone has any ideas on making a bunch of like objects attract each other, as though they all have their own gravity. The only way I can think to do it would be with a nested loop, and it seems terribly inefficient and would take up a lot of processing power.

    The effect I'm going for can be seen in here:

    Subscribe to Construct videos now

    Where a bunch of little balls clump together and writhe around in a mass with little pieces that break off and stuff.

    I've made a secondary gravity object that the little balls all move towards, but it's not quite the same effect (though kinda cool in it's own way).

    And just for the record, no, I don't actually need this for anything, it's just to satisfy my curiosity. So if you feel like helping out would be a waste of time I understand. It's basically just for fun.

  • ForEach Object nested in ForEach Object doesn't sound good. Maybe you'd try to store object X, Y, mass into some array or binary data object.

    You know:

    1. ForEach object

    -> Populate array/binary data object

    2. ForEach object

    -> for every record in object

    Maybe it'd be faster than

    1. ForEach Object

    -> ForEach Object

  • If I remember my Physics correctly, all you need to do is calculate the centre of gravity, and make everything fall towards that. This example shows that, but I don't think it's quite perfect (it doesn't take in to account that objects with a bigger mass have a greater effect on the centre of gravity). It shows the right idea though.

  • If I remember my Physics correctly, all you need to do is calculate the centre of gravity, and make everything fall towards that. This example shows that, but I don't think it's quite perfect (it doesn't take in to account that objects with a bigger mass have a greater effect on the centre of gravity). It shows the right idea though.

    That's pretty close to what I've done on my own, what with the objects all moving towards a single point, though yours is a little more sophisticated by averaging that point.

    The effect I'm looking for though is one in which each object exerts a small amount of it's own gravity, and the effect is cumulative in larger clusters. As you can see from the video, when a mass breaks apart, single stray objects and small clusters clump together rather than around a central point. Presumably if left alone they would all collapse into one big mass, but each object clearly has it's own influence.

  • If I remember my Physics correctly, all you need to do is calculate the centre of gravity, and make everything fall towards that.

    Soo, do you stay indoors during the day, so you can stand on the ceiling instead of falling into the sun?

    As I understand it, what you can do is simplify the whole complicated mess into a binary tree: In each tick, you take two objects, work out how they interact with each other only (ignoring everything else), and from then on treat them as one object with a common center of gravity (and a mass of the sum of their masses, and a velocity of the resultant vector of their individual velocities). Keep simplifying pairs of objects into single objects until you're down to two. Then you propagate the velocity changes back down the tree until all individual sprites know theirs, update the simulation and start the next tick.

  • Soo, do you stay indoors during the day, so you can stand on the ceiling instead of falling into the sun?

    Should I be doing this? Now I'm scared

    As I understand it, what you can do is simplify the whole complicated mess into a binary tree: In each tick, you take two objects, work out how they interact with each other only (ignoring everything else), and from then on treat them as one object with a common center of gravity (and a mass of the sum of their masses, and a velocity of the resultant vector of their individual velocities). Keep simplifying pairs of objects into single objects until you're down to two. Then you propagate the velocity changes back down the tree until all individual sprites know theirs, update the simulation and start the next tick.

    Took me a second to grasp the concept, but I'm lost as to how you could accomplish this with Construct events.

  • > If I remember my Physics correctly, all you need to do is calculate the centre of gravity, and make everything fall towards that.

    >

    Soo, do you stay indoors during the day, so you can stand on the ceiling instead of falling into the sun?

    No, because you have to take in to account the Earth's centre of gravity and the Earth's mass! (My example does not take in to account mass, which I noted). In reality, the centre of gravity you fall towards will be ever so slightly towards you from the centre of the Earth's gravity due to your own mass, but the effect is vanishingly small.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Made an example situation with three objects located in lovely Pitagoras triangle. Maybe I've screwed physics laws but here's the result:

    <img src="http://www.tymczasownik.republika.pl/someMath.png">

    Maybe there'd be some use of acceleration vectors counted on each of binary tree steps?

  • If I can find out the command for SQAUREROOT in Construct, I think I might be able to get this working... tried squareroot, sqrt, square, etc etc to no avail.

    Anyone know what it is?

    ~Sol

  • If I can find out the command for SQAUREROOT in Construct, I think I might be able to get this working... tried squareroot, sqrt, square, etc etc to no avail.

    Anyone know what it is?

    ~Sol

    sqrt()

  • Thanks Doppel...

    Well for starters, the formula for distance between two objects is very handy you guys:

    sqrt((Sprite.X-Sprite2.X)^2+(Sprite.Y-Sprite2.Y^2)

    Then finding the center point of that distance...

    Still not quite getting there, but getting some results... but I suck at math so I'm doing this out of pure morbid curiosity!

    ~Sol

  • sqrt((Sprite.X-Sprite2.X)^2+(Sprite.Y-Sprite2.Y)^2)

    You forked up a bit there.

  • sqrt((Sprite.X-Sprite2.X)^2+(Sprite.Y-Sprite2.Y)^2)

    You forked up a bit there.

    lol oops missed a bracket hahaha... stupid laptop keyboard for the lose!

    ~Sol

  • I actually whipped up an example of this a couple of days ago, but I kept forgetting to post it. It uses For Each loops for achieving it, but they only run every tenth of a second, which speeds it up by about 50% over all the time.

    Individual Gravity Example

    Left click for a low mass sphere and right click for a high mass sphere. Hope somebody finds it helpful.

  • Hey link I am working on a very similar thing myself... I have used three objects though... one "planet" object, with a lower mas "moon" object, then even lower mass "comet" objects.

    When two comets collide, they make a moon, and when the moons collide with the planet, the planet gains mass and the moons are destroyed.

    I will make it so the "player" can shoot the objects;

    shoot a comet, and it is destroyed

    shoot a moon and it breaks into 2 comet objects

    shoot a planet it will lose mass equal to two moon objecs, and create two moon objects

    if the planet is shot enough, it will be destroyed.

    comets at the moment are only attracted to the moon objects, and the moon objects are currently only attracted to the planet object, but the effect is rather convincing.

    I was basically trying to get a psudeo version of the video that deadeye posted.

    Instead of using xy measurements based on distance, the force applied is equal to the DISTANCE FORMULA of the objects, so if they are far away they will to to move back together more quickly... this is the opposite of what would happen in a real world experiment, but for applied mechanics in a game situation, it seems to work quite well.

    I will keep playing with it before I upload... the way your example works is probably way better than mine, so I may work with your example and include the merging and seperation of objects based on a player shooting at them.

    ~Sol

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)