Planetary gravity pls help

space

#1

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

@Mindcool24


#2

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


#3

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


#4

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


#5

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


#6

I’m not sure how to do this so sorry


#7

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!


@Mindcool24


#8

@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


#9

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!


#10

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


#11

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


#12

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”


#13

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


#14

You’re close
image

  • 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


#15

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


#16

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

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


#17

Ah ok that’s exactly what I needed


#18

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


#19

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:


#20

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

Here is the link to the project:
https://c.gethopscotch.com/p/zx2rpl762

And what it does: