Planetary gravity pls help



This topic is for a collab/discussion on how to make a solar system or moon system on hopscotch. Anyone is allowed to join. Just reply to this topic asking to be added.

Included peoples



Hey @Hopscotcher, would you like to help me with this?


Yeah, sure! You could tag pomtl for some more people who could be interested.


i can help to but i’m pretty much useless at coding


@pomtl Boom.
If you were tagged, look at top post!


I’m not sure how to do this so sorry


Well, first you can get your planet.
Get a circle and make it gray, add holes, etc.
Then, make your sun.
Make the circle/planet move in an circle/elipse , turning invisible when it touches the sun.

Like this-
Game starts
Set Variable to 0
(Repeat forever= Move forward 1, turn one)

When Planet is touching Sun
Set invisibility 100%
Set Varible to 1

Game starts
(Check once if Variable=1
Set invisibility 0)

What I “Coded” above makes the planet move in a circle, making so it looks like it’s rotating.

I could code you on my alt account if you want!



@CoderOfMagic, I was thinking of having gravity, so it is as realistic/accurate as possible, not just a circle around it
Not to offend, just to clarify


Okay! Maybe then do a eclipse instead of a circle, with a tilted axis! You could also add that the planet curves around the end of the eclipse!


I don’t think you are getting what I am saying
I want to do the orbit mathematicly, not pre-programed static orbit


Ah, now I understand!
Like math blocks and set positions?


Yes something like that… I found an accurate simulation on the internet, but I can’t find what equation/algorithm they used. IDK the exact link, but if you want to look, Google “PHET planet orbit sim”


You find an equation for planet gravity…
Where g is gravity
G is gravitational constant (6.6^-11)
r is radius


You’re close

  • The force then needs to be resolved into X and Y components

    • Calculate the angle between the 2 masses
    • Use trig to calculate X & Y components
  • Acceleration (X & Y) of each body can calculated with Newton’s 2nd Law of Motion: F=ma

  • Velocity (X & Y) can be calculated using the 1st equation of motion: Vf = V0 + at

    • V0 is the initial velocity
    • Vf is the final velocity
    • The final velocity of one frame becomes the initial velocity of the next
    • 1 frame in Hopscotch is 16.7ms (.0167s) when executing without lag
  • and finally, velocity can equate to how many pixels the masses move per frame in your project


Omg! Thanks you so much! I just can’t figure out how velocity works…


If you mean how to implement it, it’s just

Set Position
x [(self)’X Position’ + X_velocity]
y [(self)’Y Position’ + Y_velocity]


Ah ok that’s exactly what I needed


Would you like me to credit you? I would like to if that’s ok with you @ThinBuffalo


That’s entirely up to you. If you made a project you think is cool, and maybe learned something along the way, then I’m happy :smiley:


@ThinBuffalo, I got this far, but it still has problems… these are some equations that I used:

Here is the link to the project:

And what it does: