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

#1 2013-03-15 04:57:22

fencer300
New Scratcher
Registered: 2013-03-15
Posts: 3

Help with gravity?

I have tried many ways of making gravity but none work! I've gone to the wikia and tried that one but still isn't working! Any help would be appreciated.

Offline

 

#2 2013-03-16 09:16:25

ChadtheBuilder
Scratcher
Registered: 2013-02-27
Posts: 100+

Re: Help with gravity?

I do not know how to help with that, but maybe you could try to find a project on Scratch that has gravity, and then look at the code used in the game for it.


http://dl.dropbox.com/u/107729333/1360160765356.jpg

Offline

 

#3 2013-03-16 16:34:28

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Help with gravity?

Gravity means objects get constantly accelerated - you need a speed variable that goes up by the same number whenever the sprite is not standing. When the sprite hits ground, set speed to 0.
Now to make your sprite move, change its position by speed every time:

forever
  if <not <touching [ground v]>>
     change [speed v] by (0.2)
  else
    set [speed v] to (0)
  end
  change y by (speed)

Last edited by roijac (2013-03-16 16:34:43)

Offline

 

#4 2013-03-16 16:47:35

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with gravity?

roijac wrote:

Gravity means objects get constantly accelerated - you need a speed variable that goes up by the same number whenever the sprite is not standing. When the sprite hits ground, set speed to 0.
Now to make your sprite move, change its position by speed every time:

forever
  if <not (touching [ground v]?)>
     change [speed v] by (0.2)
  else
    set [speed v] to (0)
  end
  change y by (speed)

Shouldn't you be changing speed by -0.2?

With regards,

ErnieParke

Last edited by ErnieParke (2013-03-17 15:01:38)


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2013-03-17 14:59:54

fencer300
New Scratcher
Registered: 2013-03-15
Posts: 3

Re: Help with gravity?

Thanks You guys really helped! It is working now! But i have another question, how do I make a sprite throw a gernade? I know the "when (button) clicked" stuff but what should i write to make it fly half-way across the screen?

Offline

 

#6 2013-03-18 16:40:15

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with gravity?

fencer300 wrote:

Thanks You guys really helped! It is working now! But i have another question, how do I make a sprite throw a gernade? I know the "when (button) clicked" stuff but what should i write to make it fly half-way across the screen?

Well, there is a way. Just use this script:

when gf clicked
set [X Velocity v] to (3)//Starting Upwards Speed
set [Y Velocity v] to (3)//Starting Left/Right Speed
repeat until (touching [floor v]?)
 change x by (X Velocity)
 change y by (Y Velocity)
 change [Y Velocity v] by (-0.25)//Gravity
 set [X Velocity v] to ((.98) * (X Velocity))//Optional
end
Explode!

Remember to change the values a bit till you get what you want.

With regards,

ErnieParke


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2013-03-19 02:39:35

fencer300
New Scratcher
Registered: 2013-03-15
Posts: 3

Re: Help with gravity?

Thanks Erne! your aweseome!

Offline

 

Board footer