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

#1 2010-10-25 20:35:39

icecube46
Scratcher
Registered: 2010-10-23
Posts: 13

gravity

howdoumake gravity???
lol

Offline

 

#2 2010-10-25 21:12:26

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: gravity

Well that's a really broad question there... gravity can be very simple or very complex, depending on how hard you want to work on it. But to answer your question, the easiest way to add gravity to a sprite is to make a script like this:

Code:

When Green Flag Clicked
Forever If [sprite y > (whatever you want the y position of the "floor" to be)]
    change y by (a negative number of your choice)
End Forever

http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#3 2010-10-27 18:15:51

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: gravity

http://scratch.mit.edu/projects/Ratty1967UK/1207378

Try that project - it's nothing fancy, just a load of bouncing balls under the influence of gravity!

Offline

 

#4 2010-10-27 20:30:27

icecube46
Scratcher
Registered: 2010-10-23
Posts: 13

Re: gravity

Harakou wrote:

Well that's a really broad question there... gravity can be very simple or very complex, depending on how hard you want to work on it. But to answer your question, the easiest way to add gravity to a sprite is to make a script like this:

Code:

When Green Flag Clicked
Forever If [sprite y > (whatever you want the y position of the "floor" to be)]
    change y by (a negative number of your choice)
End Forever

im asuming you put a move down 5 in there

Offline

 

#5 2010-10-27 20:41:57

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: gravity

icecube46 wrote:

Harakou wrote:

Well that's a really broad question there... gravity can be very simple or very complex, depending on how hard you want to work on it. But to answer your question, the easiest way to add gravity to a sprite is to make a script like this:

Code:

When Green Flag Clicked
Forever If [sprite y > (whatever you want the y position of the "floor" to be)]
    change y by (a negative number of your choice)
End Forever

im asuming you put a move down 5 in there

"a negative number of your choice" - Yes.


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#6 2010-10-27 20:44:56

icecube46
Scratcher
Registered: 2010-10-23
Posts: 13

Re: gravity

Harakou wrote:

icecube46 wrote:

Harakou wrote:

Well that's a really broad question there... gravity can be very simple or very complex, depending on how hard you want to work on it. But to answer your question, the easiest way to add gravity to a sprite is to make a script like this:

Code:

When Green Flag Clicked
Forever If [sprite y > (whatever you want the y position of the "floor" to be)]
    change y by (a negative number of your choice)
End Forever

im asuming you put a move down 5 in there

"a negative number of your choice" - Yes.

you seem like a goos one too ask.. can you have a player draw a sprite to use as his/her character?????

Offline

 

#7 2010-10-27 20:53:06

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: gravity

icecube46 wrote:

Harakou wrote:

icecube46 wrote:


im asuming you put a move down 5 in there

"a negative number of your choice" - Yes.

you seem like a goos one too ask.. can you have a player draw a sprite to use as his/her character?????

Not in any efficient way... you can give them the option to choose from several preloaded ones, but I can't think of any good way to let them draw their own. Sorry.  sad


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#8 2010-10-27 20:58:28

icecube46
Scratcher
Registered: 2010-10-23
Posts: 13

Re: gravity

Harakou wrote:

icecube46 wrote:

Harakou wrote:


"a negative number of your choice" - Yes.

you seem like a goos one too ask.. can you have a player draw a sprite to use as his/her character?????

Not in any efficient way... you can give them the option to choose from several preloaded ones, but I can't think of any good way to let them draw their own. Sorry.  sad

ok can you show me how to be able 2 choose???

Offline

 

#9 2010-10-27 21:09:55

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: gravity

icecube46 wrote:

Harakou wrote:

icecube46 wrote:


you seem like a goos one too ask.. can you have a player draw a sprite to use as his/her character?????

Not in any efficient way... you can give them the option to choose from several preloaded ones, but I can't think of any good way to let them draw their own. Sorry.  sad

ok can you show me how to be able 2 choose???

The easiest way is just to have a sprite for each costume (in some sort of character-selection screen). Have each sprite, when it's clicked, set a variable (call it whatever you want, "character" for example.) that corresponds to the costume number on the player sprite. Then on the player sprite, have it switch to the appropriate costume with this block: "Switch to costume (character)" For example, if the second costume was Mario, then clicking on the Mario character selection sprite should set "Character" to 2. That way, the player sprite will switch to costume #2, i.e. Mario.

I hope that makes sense.


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#10 2010-10-27 21:10:17

icecube46
Scratcher
Registered: 2010-10-23
Posts: 13

Re: gravity

ok so how u make it so when it touches a platform it stops but u can still move

Offline

 

#11 2010-10-27 21:25:54

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: gravity

icecube46 wrote:

ok so how u make it so when it touches a platform it stops but u can still move

That can be done multiple ways, but the easiest is just

Code:

Forever if <not <touching color (whatever)> >
   change y by (a negative number of your choice)
End Forever

http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#12 2010-10-30 11:41:13

qwerything
New Scratcher
Registered: 2010-10-30
Posts: 1

Re: gravity

If you are doing a jagged floor this is a good script:
1st: Make a spirte called "ground", duplacate it and call that sprite "bottom ground", put it a few pixels away from "ground"
2nd :Add a variable "ignore gravity"
3rd: Add this script



when green flag clicked
forever
if ingnore gravity = 0
if touching ground
else
change y by -10


when green flag clicked
forever
if touching bottom ground
change y by 2

Offline

 

#13 2010-10-30 11:53:34

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

Re: gravity

Here is a project on how to make gravity:

http://scratch.mit.edu/projects/HD123/1343219

It is realistic, and it works for an uneven floor.

Last edited by HD123 (2010-10-30 11:53:55)


~~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

 

Board footer