# Physics gravity conundrum

For questions about using Classic.

### » Sat Sep 20, 2008 2:41 pm

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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
41
Posts: 3,032
Reputation: 30,999

### » Sat Sep 20, 2008 2:47 pm

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

You forked up a bit there.
B
2
S
2
G
4
Posts: 136
Reputation: 1,722

### » Sat Sep 20, 2008 2:53 pm

[quote="Barri167":19xy1ybg]sqrt((Sprite.X-Sprite2.X)^2+(Sprite.Y-Sprite2.Y)^2)

You forked up a bit there. [/quote:19xy1ybg]

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

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
41
Posts: 3,032
Reputation: 30,999

### » Sat Sep 20, 2008 3:29 pm

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.
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Sat Sep 20, 2008 3:51 pm

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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
41
Posts: 3,032
Reputation: 30,999

### » Sun Sep 21, 2008 12:05 am

[quote="SoldjahBoy":2jduotoj]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[/quote:2jduotoj]

The force applied is derived from 640 - distance, so if an object is 500 pixels away, the force would be 140, and if an object was 20 pixels away, it would be 620. So it is set up to where the force is correct, just only for certain distances, because if it's over 640 pixels away it's repelled. I just don't know what maths I would need to do it properly.
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Sun Sep 21, 2008 12:10 am

could just set it to where if the result is less than 0, set to 0.

but the odd behavior i noticed in link's, is how putting a heavy mass and light mass next to eachother will result in them moving out of the screen instead of the green simply coming to rest next to the gray.

also, orbiting objects almost always manage to slingshot farther away, rather than coming closer and closer.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

### » Sun Sep 21, 2008 12:53 am

[quote="dfyb":265w0f30]but the odd behavior i noticed in link's, is how putting a heavy mass and light mass next to eachother will result in them moving out of the screen instead of the green simply coming to rest next to the gray.

also, orbiting objects almost always manage to slingshot farther away, rather than coming closer and closer.[/quote:265w0f30]

Yeah, it doesn't seem to be very stable. Still, getting pretty close though as each object actually does have it's own pull.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

### » Sun Sep 21, 2008 1:25 am

[quote="deadeye":1ir17fkz][quote="dfyb":1ir17fkz]but the odd behavior i noticed in link's, is how putting a heavy mass and light mass next to eachother will result in them moving out of the screen instead of the green simply coming to rest next to the gray.

also, orbiting objects almost always manage to slingshot farther away, rather than coming closer and closer.[/quote:1ir17fkz]

Yeah, it doesn't seem to be very stable. Still, getting pretty close though as each object actually does have it's own pull.[/quote:1ir17fkz]

I didn't notice that before, but there doesn't seem to be a way I can fix it. Since the pull of an object is multiplied by it's mass, lighter objects will be pulled in faster than heavier objects and end up pushing the pulling object.
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Sun Sep 21, 2008 1:51 am

are we supposed to report instances where i can replicate a crash in our game? while attempting the gravity conundrum, i did something that always crashes instantly with the error "out of memory" when triggered in the .exe.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

PreviousNext

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 1 guest