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

#1 2012-01-29 12:42:26

iTweak0r
Scratcher
Registered: 2011-07-30
Posts: 100+

How to make gravity

to make gravity in your platformer, use these scripts

when flag clicked
forever
  if <not <touching color [ground color]?>>
    change [y velocity v] by (-0.4)
  end
  change y by (y velocity)
when flag clicked
set [y velocity v] to (0)
forever
  if <touching color [ground color]?>
    set [y velocity v] to (0)
    wait until <not <touching color [ground color]?>>
  end
when [space v] key pressed
if <touching color [ground color]?>
  set [y velocity v] to (9)
end


Make it in Scratch! because it's cooler when it's made in scratch
http://i.imgur.com/D4iqPHR.png

Offline

 

#2 2012-01-29 12:47:39

KrIsMa
Scratcher
Registered: 2011-09-20
Posts: 500+

Re: How to make gravity

Awesome. You can do this too:

whengfclicked
Forever
If <touching color [ground color]?>
Change y by (2)
Else
Change y by (-1)
End
End
Stop script

Last edited by KrIsMa (2012-01-29 12:57:43)


http://blocks.scratchr.org/API.php?user=KrIsMa&amp;action=onlineStatus&amp;online=http://i49.tinypic.com/2pzic0m.png&amp;offline=http://i49.tinypic.com/r7p10n.png
The Scratch Team (and fellow scratchers!) is/are so nice!!!

Offline

 

#3 2012-01-29 13:10:23

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: How to make gravity

I prefer:

when green flag clicked
set (y velocity) to [0]
forever
if <touching color [#36E813]?>//Change the colour in this block to the colour of the ground.
  if <key [up arrow v] pressed?>
  set [y velocity v] to (10)
  else
  set [y velocity v] to (1)
  end
 else
   change [y velocity v] by (-1)
end
change y by (y velocity)
end

Last edited by RedRocker227 (2012-03-14 15:52:27)


Why

Offline

 

#4 2012-01-29 14:15:21

FreshStudios
Scratcher
Registered: 2011-04-11
Posts: 500+

Re: How to make gravity

RedRocker227 wrote:

I prefer:

when green flag clicked
set (y velocity) to [0]
forever
if <touching color [#36E813]?>
  if <key [up arrow v] pressed?>
  set [y velocity v] to (10)
  else
  set [y velocity v] to (1)
  end
 else
   change [y velocity v] by (-1)
end
change y by (y velocity)
end

thats what i use, or something similar to that


http://i43.tinypic.com/24ymnbn.png

Offline

 

#5 2012-01-30 06:50:59

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: How to make gravity

RedRocker227 wrote:

I prefer:

when green flag clicked
set (y velocity) to [0]
forever
if <touching color [#36E813]?>
  if <key [up arrow v] pressed?>
  set [y velocity v] to (10)
  else
  set [y velocity v] to (1)
  end
 else
   change [y velocity v] by (-1)
end
change y by (y velocity)
end

My newer method used here is based off of this, but uses the new variable "energy" to determine the power of the jump. Other than that, I usually use this one.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#6 2012-01-30 07:21:22

catfan8
Scratcher
Registered: 2008-07-23
Posts: 500+

Re: How to make gravity

RedRocker227 wrote:

I prefer:

when green flag clicked
set (y velocity) to [0]
forever
if <touching color [#36E813]?>
  if <key [up arrow v] pressed?>
  set [y velocity v] to (10)
  else
  set [y velocity v] to (1)
  end
 else
   change [y velocity v] by (-1)
end
change y by (y velocity)
end

I find that a set y velocity to 0 block works better then a set y veloctiy to 1 block.


http://mag.racked.eu/cimage/i9002/Sword-In-Back+get%21/HEROBRINE+Y+U+NO+EXIST/mca.png

Offline

 

#7 2012-01-30 10:30:24

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: How to make gravity

catfan8 wrote:

RedRocker227 wrote:

I prefer:

when green flag clicked
set (y velocity) to [0]
forever
if <touching color [#36E813]?>
  if <key [up arrow v] pressed?>
  set [y velocity v] to (10)
  else
  set [y velocity v] to (1)
  end
 else
   change [y velocity v] by (-1)
end
change y by (y velocity)
end

I find that a set y velocity to 0 block works better then a set y veloctiy to 1 block.

But then the sprite won't be able to rise to the top of the ground when it goes under  hmm


Why

Offline

 

#8 2012-01-30 21:23:40

catfan8
Scratcher
Registered: 2008-07-23
Posts: 500+

Re: How to make gravity

RedRocker227 wrote:

catfan8 wrote:

RedRocker227 wrote:

I prefer:

when green flag clicked
set (y velocity) to [0]
forever
if <touching color [#36E813]?>
  if <key [up arrow v] pressed?>
  set [y velocity v] to (10)
  else
  set [y velocity v] to (1)
  end
 else
   change [y velocity v] by (-1)
end
change y by (y velocity)
end

I find that a set y velocity to 0 block works better then a set y veloctiy to 1 block.

But then the sprite won't be able to rise to the top of the ground when it goes under  hmm

Yes, but I've tested it to find that it doesn't go under either. As long as you have decent collison detection, it works great.


http://mag.racked.eu/cimage/i9002/Sword-In-Back+get%21/HEROBRINE+Y+U+NO+EXIST/mca.png

Offline

 

#9 2012-02-22 13:39:29

tayyib123
New Scratcher
Registered: 2012-02-22
Posts: 7

Re: How to make gravity

KrIsMa wrote:

Awesome. You can do this too:

whengfclicked
Forever
If <touching color [ground color]?>
Change y by (2)
Else
Change y by (-1)
End
End
Stop script

how do you move then

Offline

 

#10 2012-03-10 06:37:51

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: How to make gravity

KrIsMa wrote:

Awesome. You can do this too:

whengfclicked
Forever
If <touching color [ground color]?>
Change y by (2)
Else
Change y by (-1)
End
End
Stop script

I don't get it. You can't put anything after a "C Forever Block".


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#11 2012-03-10 06:49:35

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: How to make gravity

jontmy00 wrote:

KrIsMa wrote:

Awesome. You can do this too:

whengfclicked
Forever
If <touching color [ground color]?>
Change y by (2)
Else
Change y by (-1)
End

I don't get it. You can't put anything after a "C Forever Block".

don't put the end on forever  tongue

fixed the script


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

#12 2012-06-16 06:50:35

MikeBrain19
New Scratcher
Registered: 2012-06-16
Posts: 10

Re: How to make gravity

Hello, I'm new here. I'm having a little bit of trouble with creating a game. It has to do with firstly my life variable and making the character's life varaible decrease by five when he is touching the baddies. Can you help me?

Offline

 

#13 2012-06-17 08:18:35

HD123
Scratcher
Registered: 2009-12-05
Posts: 500+

Re: How to make gravity

MikeBrain19 wrote:

Hello, I'm new here. I'm having a little bit of trouble with creating a game. It has to do with firstly my life variable and making the character's life varaible decrease by five when he is touching the baddies. Can you help me?

when gf clicked
forever
  if <touching [baddie v]>
    change [lives v] by (-5)
    wait until <not <touching [baddie v]>>
  end
end

Last edited by HD123 (2012-06-17 08:18:48)


~~HD123~~
Treat others as you want to be treated. |  big_smile  | http://i.imgur.com/OaNrY.gif | http://blocks.scratchr.org/libstatus.php?user=HD123&amp;online=http://lemonfanatic.webs.com/ONLINE.png&amp;offline=http://lemonfanatic.webs.com/OFFLINE.png

Offline

 

#14 2012-06-18 19:54:19

captaincrunch
New Scratcher
Registered: 2012-06-17
Posts: 12

Re: How to make gravity

is it possable to make x volocity in a scrolling game?

Offline

 

#15 2012-06-18 20:26:20

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: How to make gravity

Why not make your own topic? You're more likely to get better help and advice.

And yes, you can by using variables. Make whatever keys you are using, then get the keys to change the variable, then get it to move variable steps.


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#16 2012-07-26 16:57:31

Take2
Scratcher
Registered: 2012-07-25
Posts: 29

Re: How to make gravity

big_smile  This is helpful!

Offline

 

#17 2012-10-12 13:01:22

pinnipediator
Scratcher
Registered: 2012-02-10
Posts: 500+

Re: How to make gravity

I have tried the first and third of these scripts and neither seem to work. The first one, nothing happened AT ALL and the third, the sprite floated up and up and didn't stop until it reached the top of the screen.

Offline

 

#18 2012-10-12 13:56:21

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How to make gravity

pinnipediator wrote:

I have tried the first and third of these scripts and neither seem to work. The first one, nothing happened AT ALL and the third, the sprite floated up and up and didn't stop until it reached the top of the screen.

Make sure you have every block and script, because every single one is needed.

Offline

 

#19 2012-10-13 02:28:35

pinnipediator
Scratcher
Registered: 2012-02-10
Posts: 500+

Re: How to make gravity

Ok, i will try again.

Offline

 

#20 2012-11-21 05:53:42

30-1
Scratcher
Registered: 2012-08-08
Posts: 100+

Re: How to make gravity

The best place to find help for this is on the scratch wiki.


http://i.imgur.com/ocOya7x.gif
I. Text I Based I Games I

Offline

 

#21 2012-11-21 13:45:20

KrIsMa
Scratcher
Registered: 2011-09-20
Posts: 500+

Re: How to make gravity

30-1 wrote:

The best place to find help for this is on the scratch wiki.

Necropost: Your post and the last post was 1 month away. This is called necroposting. This is frowned by the ST.

Thanks.


http://blocks.scratchr.org/API.php?user=KrIsMa&amp;action=onlineStatus&amp;online=http://i49.tinypic.com/2pzic0m.png&amp;offline=http://i49.tinypic.com/r7p10n.png
The Scratch Team (and fellow scratchers!) is/are so nice!!!

Offline

 

#22 2012-11-21 16:33:50

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: How to make gravity

I think I'll report this to be closed, since there's a lot of answers to the question out here already.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#23 2012-11-21 16:49:27

cheddargirl
Scratch Team
Registered: 2008-09-15
Posts: 1000+

Re: How to make gravity

KrIsMa wrote:

30-1 wrote:

The best place to find help for this is on the scratch wiki.

Necropost: Your post and the last post was 1 month away. This is called necroposting. This is frowned by the ST.

Thanks.

Not if the post is still relevant, which in this case, it still looks pretty relevant to me.

We actually frown upon attacking others about necroposting when it might not be the case. It's just better to flag the comment and let the Scratch Team decide if it's a bad necropost or not.


http://i.imgur.com/8QRYx.png
Everything is better when you add a little cheddar, because when you have cheese your life is at ease  smile

Offline

 

#24 2012-11-21 18:44:06

KrIsMa
Scratcher
Registered: 2011-09-20
Posts: 500+

Re: How to make gravity

cheddargirl wrote:

KrIsMa wrote:

30-1 wrote:

The best place to find help for this is on the scratch wiki.

Necropost: Your post and the last post was 1 month away. This is called necroposting. This is frowned by the ST.

Thanks.

Not if the post is still relevant, which in this case, it still looks pretty relevant to me.

We actually frown upon attacking others about necroposting when it might not be the case. It's just better to flag the comment and let the Scratch Team decide if it's a bad necropost or not.

To me, it looks very irrelevant, cause its old and there is a lot of answers already.


http://blocks.scratchr.org/API.php?user=KrIsMa&amp;action=onlineStatus&amp;online=http://i49.tinypic.com/2pzic0m.png&amp;offline=http://i49.tinypic.com/r7p10n.png
The Scratch Team (and fellow scratchers!) is/are so nice!!!

Offline

 

#25 2012-11-22 00:20:08

cheddargirl
Scratch Team
Registered: 2008-09-15
Posts: 1000+

Re: How to make gravity

KrIsMa wrote:

cheddargirl wrote:

KrIsMa wrote:


Necropost: Your post and the last post was 1 month away. This is called necroposting. This is frowned by the ST.

Thanks.

Not if the post is still relevant, which in this case, it still looks pretty relevant to me.

We actually frown upon attacking others about necroposting when it might not be the case. It's just better to flag the comment and let the Scratch Team decide if it's a bad necropost or not.

To me, it looks very irrelevant, cause its old and there is a lot of answers already.

Not to me. Old doesn't mean the thread itself is closed to posting. Next time, it's better to just report the post and let the Scratch Team handle it.


http://i.imgur.com/8QRYx.png
Everything is better when you add a little cheddar, because when you have cheese your life is at ease  smile

Offline

 

Board footer