0 Favourites

# [Solved] Physics Math question

• 5 posts
• Hello.

I'm building my first (space)game and its coming along great. I just added some physics to it which was surprisingly easy to do after a bit of reading. My planets now have gravity!

Atm i'm comparing 2 value's to see if the ship is in range for the force to take affect. Its working as intended however i would like the force to increase in strength as the ship gets closer to the planet.

I figured this could be done by dividing the force with the distance between the ship and the planet. That way the force would be lower if you are further away from the planet. The only thing is i have no idea how to set this up.

Here is a link to my test built

• ## Buy Construct 3

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

Construct 3 users don't see these ads
• Here is one way..

http://dl.dropbox.com/u/84974566/ship-planet.capx

there are lots of clever folks on here and maths is not my strong point ha, but it works. <img src="smileys/smiley1.gif" border="0" align="middle">

• You are right. =)

You can get the distance between the two with distance(Player.X,Player.Y,Sun.X,Sun.Y)

If you want to make it more realistic and make the effect of distance stronger you can square that value.

You could also give the planet/star a mass variable and use that instead of directly specifying a force. Might make things easier if you have many planets/star and use families later.

EDIT: Looks like spongehammer beat me to it! =D

• also made one haha <img src="smileys/smiley1.gif" border="0" align="middle">

gravity test

• Hey guys thanks for all the replies!

I'm not using the beta atm so i could not open your examples. Downloaded it today. Anyway I had a friend over last night and we figured it out.

Credit goes to my friend but here is what he came up with.

Apply physics force: (1-(distance(player.X,player.Y,sun.X,sun.Y)/512))/2

512 is just half of the layout size

Here's the example

• 5 posts