Using Gravity In Scratch 1.4 – Simple

Scratch 1.4 doesn’t have a gravity engine built in, which is great in some situations (games like Pac-Man), and not-so-great in others. Imagine Super Mario Galaxy without gravity! You’d jump and keep floating. Forever. A lot of people know when they NEED gravity, but not how to put it in their games. Well, here you are then. Let’s learn how to use gravity!

Making Gravity Cat

I’m going to teach you how to use gravity by making a game: Gravity Cat. It’s a green cat jumping around on a black background. It’s simple, but it proves the point.The Finished Gravity Cat.

I can give you the background here, but WordPress won’t let me keep a sprite file on this website. However all you really have to to is color the default cat’s body green.

So now you should have a stage that looks something like this:

Click to make bigger

However, there seems to be one strange thing: the cat doesn’t move when you press the green flag!!!!

So let’s set up a simple moving script for the cat:Scripts

If you hit the green flag button, you will see one tiny problem. The cat moves, but he doesn’t face the direction he’s moving in. I’ve found that it’s usually a good idea to do that.

So let’s change the script to this:Scripts2

If you click the green flag, you’ll see now we have ANOTHER bug. When you move left, the cat goes upside down!

To fix this, go to the top of the cat’s scripting area, and click the button that has the(arrow) symbol:

...Well, Click there then.

You will immediately see a change. The cat will flip right side up.

Click play again, and you will see that the game works.

…Except there’s no gravity. Sarcastic smile

Making Gravity Cat have Gravity.

The script is very easy, and it works on a simple principle.Scripts3

If the cat isn’t touching the ground, make it move down. If it is, make it move up. It can’t get simpler than that, can it?  Open-mouthed smile

Here are some challenges to try.
  1. Give the cat the ability to jump
  2. Make the cat use it’s other costume (so it looks like the pussy is walking)

As usual, have fun with this neat code!

Tags: , , , , ,

5 responses to “Using Gravity In Scratch 1.4 – Simple”

  1. sam says :

    i would like to know how to with varieables

  2. Dylan says :

    I find that method not so smooth. I like using variables to change the y-axis.

  3. Poop says :

    POOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOPPPPPPPPPPPPP HAHAHHA

  4. ScratchNerd says :

    This Is GREAT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I LOVE IT!!

  5. smee says :

    you so funny

Have something to say?