There are many different implementations of gravity for different games.
Having one built-in would reduce the flexibility in designing new games.
Offline
I agree with kevin, but having a gravity button would save a lot of time. Personally, I wonder how you would stop gravity. Here's an example of what my gravity usually is:
When [flag] clicked
forever
change y by -3
if touching color [black]
change y by 5
But that's just how I do it.
Offline
No there should not be a gravity button. People should learn how to implement gravity themselves. Scratch is simple enough with out it having every script premade for you.
Offline
Yes, I'm thinking the same. You have to implement gravity yourself. That is also the reason why i don't like the "If on edge, bounce" block. "Touching (edge) " is use full: you can program an if on edge, bounce yourself? Why it is pre-programmed in a block?
Offline
I've never used the "if on edge, bounce", because I rarely use turtle graphics (I use glide, go to, and change x,y much more than I use "move n steps"). The block has never made much sense to me. It is one of those that should be relegated to an optional library so that people could see how it is defined. (I'm still not sure exactly what its definition is---I know if changes the direction, but I'm not sure what algorithm it uses for choosing the new direction.)
Offline
I like the "if on edge, bounce" command, even though I rarely use it, because it gets you started quickly with any 'pong' kind of game or feature. Also, if your sprite moves more than 1 step at a time (or - even worse - at changing or random steps) it would be rather complex to implement a "bounce" script yourself, because you'd have to constantly check if your sprite would *still* be touching the edge, and then decide if to again change direction or not.
Offline
you can program an if on edge, bounce yourself? Why it is pre-programmed in a block?
Its a command for young (at heart) minds :-)
To make a sprite "bounce" (it actually implements a wave type reflection) off the sides without having to do things like:- if on edge - if (top or bottom edge) - turn in (direction-180) - else turn in (180-direction) - endif -move 10 steps - endif.
(Code just for illustration - I can't remember which way round you have to code top/bottom vs left/right edge detection ! :-) )
I REALLY REALLY want it expanded so you can "bounce" off any sprite and not just the edge but every time I vote for it Kevin votes against, so I can never get enough support :-)
One day, he'll come round :-)
regards
Simon
PS Jens - your on my Christmas card list this year :-)
Last edited by SimpleScratch (2007-12-13 01:48:39)
Offline
<when[ blah ]key pressed>
<forever>
jump up and down like a monkey
<end>
thats usually how i make gravity
Offline
Bouncing correctly off a sprite is not as easy as bouncing off an edge, because doing it right depends on the shape and orientation of the sprite. If you are interested in seeing some code for bouncing off of straight lines, circles, and the insides of circles, see the School Pinball game: http://scratch.mit.edu/projects/kevin_and_abe/54377
The bounce is done by the ball, but it has to get orientation information from the object it is bouncing off of. There are comments in the code (thanks to version 1.2 beta) that explain the variables, messages, and methods.
Offline
I'd find it really helpful. I can't do gravity and am forever searching the forums for how to do it. No luck so far.
Offline
As Kevin mentioned, "Gravity" may mean different things to different Scratchers, so a Gravity "button" doesn't really make sense.
Gravity can mean acceleration in negative y (down on the screen) or it might mean acceleration toward another sprite. To simulate the gravity of a planet, the programmer would want gravity to vary (inversely) with the square of distance to the planet. Also, depending on what is desired, Gravity would likely only act on certain sprites in a game or simulation. The makes the meaning (and usefulness) of a Gravity "button" questionable.
For ideas on implementing "gravity", you would do best to search in the galleries or projects. If you are stumped, post a project that you'd like to add gravity to, and descibe what you would like gravity to do. That will allow someone to download your project and help you out.
I've done several projects with gravity, below are a couple of projects. Note that there are other ways to program gravity, I'm posting these links to illustrate two different "meanings":
http://scratch.mit.edu/projects/EdnaC/48110
http://scratch.mit.edu/projects/EdnaC/37711
-Mr Ed
Offline
More thoughts on "if on edge, bounce":
One reason that people find this so useful, is that the appropriate tests needed to implement it yourself are not provided to the Scratch programmer. I know, someone is about to remind me that there is a "touching edge" block. Indeed there is, but to figure out the bounce, you have to know *which* edge, and figuring out that is not really possible in scratch, since the touching test uses information about the shape of the costume that isn't available to the scratch programmer. You can make approximations (based, for example, on assuming a circular sprite), but they won't necessarily work right in the corners.
But, if we had
touching top edge
touching bottom edge
touching right edge
touching left edge
as separate tests, we could implement "if touching edge, bounce" ourselves:
if touching top edge or touching bottom edge
set direction 180 - direction
if touching right edge or touching left edge
set direction 0 - direction
Actually, I think the implementation is a little fancier, in that it involves moving 1 pixel away from the edge as well as changing direction. I'm not 100% sure of this though.
Offline
Maybe it will cause problems in the corners of the scratch field...
Yes, allowing top.bottom,etc would be good. You can program it yourself, (i've done it in a flash game, you have to calculate in what corner of the screen you are, if touching edge), but the script for that was (at that moment) very hard for me to find out.
Offline
Actually, scratch only allows you to guess what edge you are touching, as there is no information available to the programmer about the shape of the costume. You can set up a costume with the rotation center a long way from any visible pixels, so that the sprite touches the top edge when its center is near the bottom edge.
Offline
But, if we had
touching top edge
touching bottom edge
touching right edge
touching left edge
as separate tests, we could implement "if touching edge, bounce" ourselves
Kevin - you are getting further and further away from Nirvana :-)
The youth of today (<12 years old) doesn't want to implement it themselves - they just want it to happen :-)
They just want things to bounce off each other so that can easily make games :-)
I want them to have it so they can get a good result quickly and latch into Scratch and move onwards and upwards :-)
regards
Simon
Offline
I want both—for kids to enjoy Scratch, doing things quickly, and for them to learn how to do it themselves and not have to rely on pre-written code.
I'm looking forward to the day when Scratch has libraries of user-definable blocks, and only a bare minimum of primitives, so that kids can see how magic like "if on edge, bounce" can be done.
Offline
Wait-
Does that mean that eventually it will have definable blocks?
Offline
Definable blocks have been near the top of the request list for some time. I believe that the Scratch team is looking into how to design a good user interface for them for some time, but I don't think that they have started coding anything for them yet. (I'm not on the Scratch team, so I'm just guessing about what they are doing.)
Offline