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

#1 2010-09-12 06:40:44

helltank
Scratcher
Registered: 2010-05-21
Posts: 1000+

Helltank's Noob Guide Part 1:Gravity

Welcome to Helltank's Noob Guide! This guide covers commonly used features or scripts of Scratch that noobs will find useful. Today, we're going to discuss gravity.

Now, imagine you're playing a platformer game that you made. As the ripped-off Mario sprite leaps over Bowser, you sit back and allow him to fall on the infamous switch, causing the bridge to dissapear and Bowser to die. But something's wrong-Mario isn't falling! Jumping to your feet, you start making a script that allows Mario to fall... and don't know where to start. You need a teacher desperately! Fortunately, here I am!

Now, we're going to split this into 2 sections: the part where I show you the script and the part where we analyse it. Now, you may be wondering why we need to analyse it. Just show me the thing and I'll duplicate it into Scratch! Here's why:You need to understand how the code works. Let's say the ruler of the universe decided to destroy all posts teaching you how to simulate gravity in Scratch. And you forgot the code. No worries, you understood how it works, so you can write it again! But enough talk. Let's start!

Section 1
When Green Flag Clicked
Set Variable Y Velocity to 2
Forever
If
Not touching Green(or whatever color the ground is)
Change Y by Y Velocity
Change variable Can Jump? to No(make sure Can Jump? must be yes in order to jump)
Change Variable Y Velocity by 2
End if
End forever

There! Now we'll see how this beast of a script(at least to you noobs-I've seen 56 block scripts...)works.

Section 2
The first block of the script is:When green flag clicked. This is to ensure that when the game starts, this script is already running.

Set variable Y Velocity to 2: This is to set your velocity. Pretty obvious, isn't it?

Then, Forever. Of course, you don't want this script to be executed only once.

Next-If not touching green. This is to ensure that you only get sucked downwards when you're actually in the air and do not sink through the floor.

Change Y by -2. That sucks you downwards. If the number is not negative, you'll fly. Just a sidenote.

Change variable Can Jump? to no. So you can't rejump in midair... and do it again. And again. And again.

Change variable Y Velocity by 1. This ensures that, well, the velocity works.


I hoped this helps! More importantly, I hope you understood how the script works and how to apply it in your project.

PS:Look out for Helltank's Noob Guide Part 2:Animation

Last edited by helltank (2010-09-13 04:17:53)


Error:Signature could not load. Please wait for an indefinite amount of time, until you realize you're gullible and go off to look for another potentially interesting signature to stare at.

Offline

 

#2 2010-09-12 09:03:06

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Helltank's Noob Guide Part 1:Gravity

Hey, you forgot to add how to do realistic gravity, or variable Y. The one where it speeds up the farther you fall. If you need help with that script Helltank, just ask.

Offline

 

#3 2010-09-12 09:17:29

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Helltank's Noob Guide Part 1:Gravity

Great guide! I would suggest adding what TheSaint mentioned - a velocity variable.  smile

Offline

 

#4 2010-09-12 11:21:38

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Helltank's Noob Guide Part 1:Gravity

No need for a "can jump" variable if your ground is all the same color- just say "if touching color AND key up arrow pressed,do jump script" Otherwise, good tutorial  smile


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#5 2010-09-12 14:51:57

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Helltank's Noob Guide Part 1:Gravity

Sunrise-Moon wrote:

No need for a "can jump" variable if your ground is all the same color- just say "if touching color AND key up arrow pressed,do jump script" Otherwise, good tutorial  smile

The can jump variable allows for more clauses to be fufuilled and more varieties of floors to be used.

Basically, it allows you to do more stuff.

Offline

 

#6 2010-09-13 04:13:42

helltank
Scratcher
Registered: 2010-05-21
Posts: 1000+

Re: Helltank's Noob Guide Part 1:Gravity

Okay, editing post... I'm going to add velocity. If you have a better script or a shortcut, please tell me.


Error:Signature could not load. Please wait for an indefinite amount of time, until you realize you're gullible and go off to look for another potentially interesting signature to stare at.

Offline

 

Board footer