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

#1 2012-03-25 10:59:41

killersnowgoon1
Scratcher
Registered: 2012-03-25
Posts: 1

Gravity

Does anybody have an idea for gravity scripts

Offline

 

#2 2012-03-25 11:35:18

ftf841
Scratcher
Registered: 2012-02-19
Posts: 1000+

Re: Gravity

when gf clicked
forever
if <not <<touching [ground v]> >
change y by (-something)


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Hi+there./mca.png
http://mag.racked.eu/mcimage/i354/Achievement++get%21/CAKE%21%21%21%21%21/mca.png

Offline

 

#3 2012-03-25 11:38:17

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Gravity

ftf841 wrote:

when gf clicked
forever
if <not <touching [ground v]?> >
change y by (-something)

Scratchblocks fixed.   smile

Offline

 

#4 2012-03-25 12:50:29

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Gravity

This should do it

When gf clicked
set [y-vel] to (0)
forever
if<([abs] of (y-vel)) < (0.1)>
change y by (-1)
if<not <touching [ground v]?> >
change [y-vel] by (-0.2)
end
change y by (1)
else
change y by (y-vel)
if<touching [ground v]?>
set [y-vel] to ((y-vel)*(-0.5))
change y by (y-vel)
if<touching [ground v]?>
change y by (y-vel)
end
end
end
end

Last edited by MoreGamesNow (2012-03-25 12:50:59)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-03-25 13:00:28

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Gravity

MoreGamesNow wrote:

This should do it

When gf clicked
set [y-vel] to (0)
forever
if<([abs] of (y-vel)) < (0.1)>
change y by (-1)
if<not <touching [ground v]?> >
change [y-vel] by (-0.2)
end
change y by (1)
else
change y by (y-vel)
if<touching [ground v]?>
set [y-vel] to ((y-vel)*(-0.5))
change y by (y-vel)
if<touching [ground v]?>
change y by (y-vel)
end
end
end
end

Velocity isn't required, considering the question.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#6 2012-03-25 13:18:19

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Gravity

bobbybee wrote:

Velocity isn't required, considering the question.

Doesn't "gravity scripts" imply acceleration and velocity?  In any case, I would prefer "gravity" with acceleration to a constant falling speed, and presumed that killersnowgoon1 would too.

Last edited by MoreGamesNow (2012-03-25 13:18:24)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-03-25 13:47:55

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Gravity

Velocity is probably better.  If you can do it a better way, why not do it?

Offline

 

#8 2012-03-25 13:50:28

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Gravity

Greenatic wrote:

Velocity is probably better.  If you can do it a better way, why not do it?

Well, the first script was a quarter of the size of the velocity script...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#9 2012-03-25 15:54:55

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Gravity

bobbybee wrote:

Greenatic wrote:

Velocity is probably better.  If you can do it a better way, why not do it?

Well, the first script was a quarter of the size of the velocity script...

And will also get the sprite stuck in the ground, as well as falling at a constant velocity  hmm   Just because my script is longer doesn't mean it is less effective or an incorrect answer.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-03-25 17:05:23

ftf841
Scratcher
Registered: 2012-02-19
Posts: 1000+

Re: Gravity

MoreGamesNow wrote:

bobbybee wrote:

Greenatic wrote:

Velocity is probably better.  If you can do it a better way, why not do it?

Well, the first script was a quarter of the size of the velocity script...

And will also get the sprite stuck in the ground, as well as falling at a constant velocity  hmm   Just because my script is longer doesn't mean it is less effective or an incorrect answer.

it works perfectly for me


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Hi+there./mca.png
http://mag.racked.eu/mcimage/i354/Achievement++get%21/CAKE%21%21%21%21%21/mca.png

Offline

 

#11 2012-03-25 17:41:13

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Gravity

ftf841 wrote:

it works perfectly for me

It does work if your goal is to make your sprite move downward until it hits the floor.  But you'll end up "inside" the floor (you stop falling after you hit the ground), and you don't accelerate.  Since the original post asked for gravity, I assumed acceleration.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#12 2012-04-04 12:48:20

P110
Scratcher
Registered: 2011-04-12
Posts: 500+

Re: Gravity

Woah! Nice scripts, I need these for an angry birds based game, (both of them, i'm not taking sides on this)


Me live on 2.0 now  sad

Offline

 

#13 2012-04-11 10:24:13

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Gravity

If you are doing angry birds game, check out my  "Help with parabolas, sine, cosine, and tangents" forum post under "help with scripts." It explains how to create gravity and shooting power.


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#14 2012-04-11 10:45:23

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Gravity

forever 
if <touching color [#000000]?> // ground colour
 set [yvel v] to [0]
else
 if <(yvel) > [-20]> //so you cant fall faster than 20 pixels per step
  change [yvel v] by (-0.1) //the higher this value, the faster you will fall. Experiment.
 end
 change y by (yvel)
end

when i receive [jump v]
if <touching color [#000000]?>
 set [yvel v] to (20)
 change y by (20) //otherwise you will still be touching the ground and it won't work

Last edited by joefarebrother (2012-04-11 10:45:58)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer