This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-07-06 09:47:55

teguki
Scratcher
Registered: 2008-03-06
Posts: 72

grav wells

how can i make a gravity well? ive tried lots of scripts but none of them work properly.

im making a space game and i want the missiles, ships, etc. to be affected by the gravitational feild of the planets (and the sun)

Offline

 

#2 2008-07-07 13:43:05

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: grav wells

One method is this
Inside a forever loop (it could be one you are already using) put this script:
point towards [gravity well]
move (100/(distance to [gravity well])*(distance to [gravity well]) steps


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#3 2008-07-09 14:24:44

teguki
Scratcher
Registered: 2008-03-06
Posts: 72

Re: grav wells

yeh, that the one im using, but the object also has its own trajectory (the direction of the mouse when it was launched), so making it point toward the planet messes up the movement. also, there are lots of planets, as Colonisation is all about conquering planets, so that makes a very long (and laggy) script, considering that there will be lots of ships, missiles, etc.

Offline

 

#4 2008-07-09 14:41:10

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: grav wells

If you are familiar with vectors...that would be a pretty straight forward way to go.  With vectors, you use trigonometry (Sin, Cos) to break all the forces down into their horizontal and vertical components (X,Y).  Then, you use classical physics to get the accelerations and so on.  Take a look at EdnaC's work, he's done a lot with gravity around planets.

http://scratch.mit.edu/projects/EdnaC/110327


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2008-07-10 07:22:34

teguki
Scratcher
Registered: 2008-03-06
Posts: 72

Re: grav wells

lol your reply just made my head explode (trig hw at the hols? > sad  XD)

but wtheck ill just follow the link

Offline

 

Board footer