Welcome to some of my tutorials for scratch. If the tutorial you need isn't here, just comment below asking for it.
Let me start by answering a lot of 'how do you do' questions that I see on the forums a lot.
Gravity
Gravity is pretty easy to make once you know how.
Put together a script as shown below.
(OPTIONAL)
If you would like to make more accurate sensing, copy the main costume of your sprite.
Then right click the copied costume and turn it into a new sprite.
Edit the costume and draw a line where you would like the sprite to stop when the line touches the ground.
Then using the rectangle tool, select the gray and white checkered color of the color chart on the bottom left corner of the paint editor and make two rectangles, one above the green line, and one below it, covering the character but not harming the line.
Press 'OK' and then put together a script as shown below for the line's scripts.
Go back to the sprite you control and add this to the script.
...And there you go! That's a good way to do gravity without getting too advanced. Let me explain how it works.
The variable 'Y Velocity' changes the Y position of the sprite. When it's not touching the ground, it changes the 'Y Velocity' variable by -1, causing the sprite to go down faster and faster. But when it's touching the ground, it sets it to 1. Why not 0? Because when it's 1, it changes the Y Velocity variable by -1 setting the variable to 0 and since the sprite is still touching the ground, sets the y velocity variable to 1 and it keeps on doing that causing the sprite not to move. The reason the other script was added is to keep the sprite to sink into the ground when it hits it. When the sprite jumps to the ground from a high area, he goes down a little into the ground until he stops. The invisible line that goes to him forever fixes that. When the invisible line touches the ground, it sets a variable to 1, causing the other sprite to change it's Y position by 5, until the invisible line isn't touching the ground.
(NOTE: In the pictures with comment blocks, the comment blocks are behind the script, the two different comment blocks say, (Color of Ground), and, (Sprite Name). Sorry about that happening, it won't happen in the next tutorial I make)
If you didn't understand something, please comment.
Hoped this helped you,
dsdude10
Last edited by dsdude10 (2009-03-09 20:53:43)
Offline
Offline