Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Changing the speed of an object
- Notester82
-
53 posts
Changing the speed of an object
How do you change the speed for an object?
Last edited by Notester82 (Feb. 15, 2014 21:37:21)
- ErnieParke
-
1000+ posts
Changing the speed of an object
Have you ever heard of velocity? It's basically the same thing as speed, but when you turn it into a variable, you can do so much more with it. For example, take a look at this code:
Your velocity is 5, so your speed is 5 pixels. It's like 5 mph or 5 meters per minute, except in pixels. So you move 5 pixels each time the script is run. Now, let's say we want to slow down to a stop. A slight change to your code would do that:
Each time the script is run, your velocity is decreased slightly, so you don't move as far. When you run the script enough times, you slow down to a stop. Do you see how it all works?
Anyway, what you'll need is the first script I showed you. Whenever you want to change/set your speed, do it to (X Velocity). You should be able to change your speed now!
Showing,
ErnieParke
when gf clicked
set [X Velocity v] to (5)
forever
change x by (X Velocity)
Your velocity is 5, so your speed is 5 pixels. It's like 5 mph or 5 meters per minute, except in pixels. So you move 5 pixels each time the script is run. Now, let's say we want to slow down to a stop. A slight change to your code would do that:
when gf clicked
set [X Velocity v] to (5)
forever
change x by (X Velocity)
set [X Velocity v] to ((X Velocity) * (0.98))
Each time the script is run, your velocity is decreased slightly, so you don't move as far. When you run the script enough times, you slow down to a stop. Do you see how it all works?
Anyway, what you'll need is the first script I showed you. Whenever you want to change/set your speed, do it to (X Velocity). You should be able to change your speed now!
Showing,
ErnieParke
- Notester82
-
53 posts
Changing the speed of an object
You can do the same thing with Y, right?
- Notester82
-
53 posts
Changing the speed of an object
when green flag clicked
forever
glide () secs to x: () y: ()
change x by (X Velocity)
change y by (Y Velocity)
end
Would the glide () secs to x: () y: () script effect the velocity?
Last edited by Notester82 (Feb. 15, 2014 22:22:07)
- 1234abcdcba4321
-
1000+ posts
Changing the speed of an object
Remove the glide block.
You shouldn't have it if you have a platformer.
You shouldn't have it if you have a platformer.
- Notester82
-
53 posts
Changing the speed of an object
This is the project I'm using velocity on.. http://scratch.mit.edu/projects/17992027/
I wanted the target to change speeds as it moves around but I didn't really think I was using the scripts the right way..
How could I fix this?
I wanted the target to change speeds as it moves around but I didn't really think I was using the scripts the right way..
How could I fix this?
Last edited by Notester82 (Feb. 15, 2014 22:56:53)
- VIC6492
-
3 posts
Changing the speed of an object
That's all great but i need a code that can make the time spent jumping in the air affected by the speed of an object
when green flag clicked
forever
if <<key [ up] pressed?>> then
change y by (70)
wait ( ) secs
change y by (-70)
- mstone326
-
1000+ posts
Changing the speed of an object
Not sure why that kept putting my response in a scratch block.
Anyway, to VIC6492. You should create your own topic so the original question can be answered and closed. We can certainly help with your question.
Anyway, to VIC6492. You should create your own topic so the original question can be answered and closed. We can certainly help with your question.
Last edited by mstone326 (July 3, 2017 21:48:31)
- RemixHelper
-
33 posts
Changing the speed of an object
when green flag clicked
set [Speed] to [10]
forever
move (Speed) steps
change [Speed] by (1)
end
Last edited by RemixHelper (July 4, 2017 03:04:37)
- -frostyiceprincess-
-
1000+ posts
Changing the speed of an object
Please don't bump old topics - that's called necroposting. Check the date of the last post. That was a year ago! If you need help, just make a separate topic/thread in the appropriate forum. how?
Thanks!

- Tpenguin213
-
1 post
Changing the speed of an object
when green flag clicked
forever
if <> then<[(speed)] = [1]>
change [ speed] by ()
end
end
- Discussion Forums
- » Help with Scripts
-
» Changing the speed of an object