"Velocity" is just the name of a variable, just because it is named velocity doesn't make a difference.
However, if you want to know how to use velocity in one of your games I can help.
Let's start with "Y Velocity":
Using yVelocity will help if you want to make good jumping scripts for your games.
To start this session of testing arrange the stage like this:
If the image doesn't load go to this link: http://img144.imageshack.us/my.php?image=stage.gif
Then in the Cat sprite make this script:
If the image doesn't load go to this link: http://img519.imageshack.us/my.php?image=picture4kef.png
Text of the comment block (if you can't read it):
This is a basic jumping script. We'll start by breaking it down. The first if statement with the set yVelocity to 0 block in it is their so the cat will not fall through the ground. The next if with the set yVelocity to 15 block in it will function if the cat is on the ground and the up arrow is pressed and will make the cat jump.
Out of that set of ifs the change y by yVelocity will make him fall or rise depending on the velocity variable. And the change yVelocity by -1 is gravity.
Remember that you can change the 15 in the;
block to make the cat jump higher!
That covers Y Velocity I'll post a tutorial for X Velocity in a little.
X Velocity:
"xVelocity" will help you make movement along the X Axis seem more realistic.
Start by arranging your stage like this:
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=stage2.gif
Then in the Cat sprite make the following script:
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=picture6zrl.png
Text of the comment block (if you couldn't read it):
This is the basic script needed to move a sprite along the X Axis with velocity. maxSpeed can be any number you won't depending on how fast you want your sprite to go. The first two if statements will change the xVelocity variable by certain numbers. These numbers can change if you want the sprite to move faster.
The next if-else will make the sprite point in the direction he is moving.
The block: change x by xVelocity will make him move depeding on how fast he is going. The last block is friction and will make the sprite eventually slow to a halt
Now if you combine these two scripts you have perfect jumping and running. I hope this helped answer your questions. If you need any further information post your question and I'll reply as soon as possible.
Last edited by demosthenes (2010-05-09 09:22:44)
Offline
That's some nice stuff! I'm sure this will help a lot.
Thank you!
Offline
demosthenes wrote:
"Velocity" is just the name of a variable, just because it is named velocity doesn't make a difference.
However, if you want to know how to use velocity in one of your games I can help.
Let's start with "Y Velocity":
Using yVelocity will help if you want to make good jumping scripts for your games.
To start this session of testing arrange the stage like this:
http://img144.imageshack.us/my.php?image=stage.gif
If the image doesn't load go to this link: http://img144.imageshack.us/my.php?image=stage.gif
Then in the Cat sprite make this script:
http://img519.imageshack.us/my.php?imag … re4kef.png
If the image doesn't load go to this link: http://img519.imageshack.us/my.php?image=picture4kef.png
Text of the comment block (if you can't read it):
This is a basic jumping script. We'll start by breaking it down. The first if statement with the set yVelocity to 0 block in it is their so the cat will not fall through the ground. The next if with the set yVelocity to 15 block in it will function if the cat is on the ground and the up arrow is pressed and will make the cat jump.
Out of that set of ifs the change y by yVelocity will make him fall or rise depending on the velocity variable. And the change yVelocity by -1 is gravity.
Remember that you can change the 15 in the;
http://img406.imageshack.us/img406/8998/picture5a.png
block to make the cat jump higher!
That covers Y Velocity I'll post a tutorial for X Velocity in a little.
X Velocity:
"xVelocity" will help you make movement along the X Axis seem more realistic.
Start by arranging your stage like this:
http://img149.imageshack.us/my.php?image=stage2.gif
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=stage2.gif
Then in the Cat sprite make the following script:
http://img149.imageshack.us/my.php?imag … re6zrl.png
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=picture6zrl.png
Text of the comment block (if you couldn't read it):
This is the basic script needed to move a sprite along the X Axis with velocity. maxSpeed can be any number you won't depending on how fast you want your sprite to go. The first two if statements will change the xVelocity variable by certain numbers. These numbers can change if you want the sprite to move faster.
The next if-else will make the sprite point in the direction he is moving.
The block: change x by xVelocity will make him move depeding on how fast he is going. The last block is friction and will make the sprite eventually slow to a halt
Now if you combine these two scripts you have perfect jumping and running. I hope this helped answer your questions. If you need any further information post your question and I'll reply as soon as possible.
Hey! I finaly did it without the blocks << <and> <( <abs( <{ xVelocity }> <<> <{ maxSpeed }> )> >> at X Velocity icon - tutorial. Thank you!
Last edited by piko_12 (2009-04-23 08:24:50)
Offline
This just explains the code from http://scratch.mit.edu/projects/archmage/72848
Offline
If anyone wants to use or look at the scripts here: http://scratch.mit.edu/projects/Llamalover/92546 .
If you use in a project, I'd like it if you credit, but as long as you don't claim it's your own, I don't mind!
Offline
Brilliant help for my projects! Thanks! It was kind to share your secret of great jumping and running to everyone on the Scratch forums.
Offline
What does the "Abs" do in the Xvelocity tutorial?
Offline
abs is short for absolute, it means that even if you use it on a negative or positive number it will be negative. I don't think you use it in velocity.
Offline
ABS makes numbers positive not negative
Offline
Ummmmmm, when I press the left arrow key, the cat turns upside down. Why is that???
Offline
Adamman715 wrote:
Ummmmmm, when I press the left arrow key, the cat turns upside down. Why is that???
It is because you did not set it to only point left-right. To fix this either make it so that when the left arrow is pressed, it will switch into a costume that is flipped.
or click a button...
Offline
<turn cw( )degrees><go to x )y
<point towards( <point towards( <point towards( <go to x
)y
<point towards( <point towards( <turn cw( )degrees><turn cw( )degrees><change{ }by( <set{ }to( <{ }><set{ }to( <play sound[ <play sound[ <play sound[ ]and waits><play sound[ ]and waits><play sound[ ]and waits><play sound[ ]and waits><touching[ <color[ ]is over[ <color[ ]is over[ <color[ ]is over[ <key[ ]pressed?><mouse down?><mouse down?><mouse x><mouse x><mouse y><touching color[
Offline
piko_12 wrote:
demosthenes wrote:
"Velocity" is just the name of a variable, just because it is named velocity doesn't make a difference.
However, if you want to know how to use velocity in one of your games I can help.
Let's start with "Y Velocity":
Using yVelocity will help if you want to make good jumping scripts for your games.
To start this session of testing arrange the stage like this:
http://img144.imageshack.us/my.php?image=stage.gif
If the image doesn't load go to this link: http://img144.imageshack.us/my.php?image=stage.gif
Then in the Cat sprite make this script:
http://img519.imageshack.us/my.php?imag … re4kef.png
If the image doesn't load go to this link: http://img519.imageshack.us/my.php?image=picture4kef.png
Text of the comment block (if you can't read it):
This is a basic jumping script. We'll start by breaking it down. The first if statement with the set yVelocity to 0 block in it is their so the cat will not fall through the ground. The next if with the set yVelocity to 15 block in it will function if the cat is on the ground and the up arrow is pressed and will make the cat jump.
Out of that set of ifs the change y by yVelocity will make him fall or rise depending on the velocity variable. And the change yVelocity by -1 is gravity.
Remember that you can change the 15 in the;
http://img406.imageshack.us/img406/8998/picture5a.png
block to make the cat jump higher!
That covers Y Velocity I'll post a tutorial for X Velocity in a little.
X Velocity:
"xVelocity" will help you make movement along the X Axis seem more realistic.
Start by arranging your stage like this:
http://img149.imageshack.us/my.php?image=stage2.gif
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=stage2.gif
Then in the Cat sprite make the following script:
http://img149.imageshack.us/my.php?imag … re6zrl.png
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=picture6zrl.png
Text of the comment block (if you couldn't read it):
This is the basic script needed to move a sprite along the X Axis with velocity. maxSpeed can be any number you won't depending on how fast you want your sprite to go. The first two if statements will change the xVelocity variable by certain numbers. These numbers can change if you want the sprite to move faster.
The next if-else will make the sprite point in the direction he is moving.
The block: change x by xVelocity will make him move depeding on how fast he is going. The last block is friction and will make the sprite eventually slow to a halt
Now if you combine these two scripts you have perfect jumping and running. I hope this helped answer your questions. If you need any further information post your question and I'll reply as soon as possible.Hey! I finaly did it without the blocks << <and> <( <abs( <{ xVelocity }> <<> <{ maxSpeed }> )> >> at X Velocity icon - tutorial. Thank you!
I Did it with other blocks! (no varablile)
Offline
Adamman715 wrote:
Ummmmmm, when I press the left arrow key, the cat turns upside down. Why is that???
Try not using pointing try using X and Y stuff. that way it works! hope it helps!
________________________________________
If you try to read upsidedown text, you wont belive it!
Offline
Wow a long script?
Offline
demosthenes wrote:
"Velocity" is just the name of a variable, just because it is named velocity doesn't make a difference.
However, if you want to know how to use velocity in one of your games I can help.
Let's start with "Y Velocity":
Using yVelocity will help if you want to make good jumping scripts for your games.
To start this session of testing arrange the stage like this:
http://img144.imageshack.us/img144/416/stage.gif
If the image doesn't load go to this link: http://img144.imageshack.us/my.php?image=stage.gif
Then in the Cat sprite make this script:
http://img213.imageshack.us/ifs/2088/im … re4kef.png
If the image doesn't load go to this link: http://img519.imageshack.us/my.php?image=picture4kef.png
Text of the comment block (if you can't read it):
This is a basic jumping script. We'll start by breaking it down. The first if statement with the set yVelocity to 0 block in it is their so the cat will not fall through the ground. The next if with the set yVelocity to 15 block in it will function if the cat is on the ground and the up arrow is pressed and will make the cat jump.
Out of that set of ifs the change y by yVelocity will make him fall or rise depending on the velocity variable. And the change yVelocity by -1 is gravity.
Remember that you can change the 15 in the;
http://img406.imageshack.us/img406/8998/picture5a.png
block to make the cat jump higher!
That covers Y Velocity I'll post a tutorial for X Velocity in a little.
X Velocity:
"xVelocity" will help you make movement along the X Axis seem more realistic.
Start by arranging your stage like this:
http://img149.imageshack.us/img149/3343/stage2.gif
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=stage2.gif
Then in the Cat sprite make the following script:
http://img149.imageshack.us/img149/2018/picture6zrl.png
If the picture doesn't load go to this page: http://img149.imageshack.us/my.php?image=picture6zrl.png
Text of the comment block (if you couldn't read it):
This is the basic script needed to move a sprite along the X Axis with velocity. maxSpeed can be any number you won't depending on how fast you want your sprite to go. The first two if statements will change the xVelocity variable by certain numbers. These numbers can change if you want the sprite to move faster.
The next if-else will make the sprite point in the direction he is moving.
The block: change x by xVelocity will make him move depeding on how fast he is going. The last block is friction and will make the sprite eventually slow to a halt
Now if you combine these two scripts you have perfect jumping and running. I hope this helped answer your questions. If you need any further information post your question and I'll reply as soon as possible.
But It keeps falling throught the ground, when I move!
Offline
coolstuff wrote:
donutking wrote:
I did everything right for the gravity part, but my sprite won't move! I copied everything EXACTLY!
![]()
Can you post a picture of your scripts so we can see what's wrong? Or maybe upload it?
Nevermind, but I copied everything right from the gravity part of the first forum comment, and now it keeps falling through the ground when I move!
Offline