[Solved] Physics Math question

0 favourites
  • 5 posts
From the Asset Store
Logo Quiz with 150 prepared logos and answers, automatic question and answer mixing
  • 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

    dl.dropbox.com/u/139739932/test/grafity%20test.capx

  • 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">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    http://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation

    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

    dl.dropbox.com/u/139739932/test/gravity%20test%202.capx

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