Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make Sprites Move Smoothly
- Lachiepower0402
-
New Scratcher
7 posts
How to make Sprites Move Smoothly
Hi,
Could anyone please tell me how to make sprites smoothly, for example my project is a car and at the moment I have it set to
Change x by -10 to go left
Change x by 10 to go right
But when I do this the car moves in steps.
Could anyone please tell me how to make sprites smoothly, for example my project is a car and at the moment I have it set to
Change x by -10 to go left
Change x by 10 to go right
But when I do this the car moves in steps.
- zanzolo
-
Scratcher
66 posts
How to make Sprites Move Smoothly
One way would be something like this: It moves by one pixel at a time, and does it 10 times
when green flag clicked
forever
if <key [left arrow] pressed?> then
repeat (10)
change x by (-1)
end
end
if <key [right arrow] pressed?> then
repeat (10)
change x by (1)
end
end
end
- lifesalibrary4me
-
Scratcher
43 posts
How to make Sprites Move Smoothly
I just use the glide __ seconds to x:__ y:__, but that’s just because I do animations. If you are doing a game it would be harder.
- zanzolo
-
Scratcher
66 posts
How to make Sprites Move Smoothly
I just use the glide __ seconds to x:__ y:__, but that’s just because I do animations. If you are doing a game it would be harder.
Glides are great for somethings.
I don't like them for games though because once you start a glide you pretty much have to finish it.
- Lachiepower0402
-
New Scratcher
7 posts
How to make Sprites Move Smoothly
The first post works quite well but it is too slow for what I am doing, is their any way to have the same thing but faster?
- AonymousGuy
-
Scratcher
1000+ posts
How to make Sprites Move Smoothly
The first post works quite well but it is too slow for what I am doing, is their any way to have the same thing but faster?Try the following:
when gf clickedThe sprite will jump by 10 pixels each time, but it should look smooth because it is in a continuous loop.
forever
if <key [right arrow v] pressed?> then
change x by (10)
end
if <key [left arrow v] pressed?> then
change x by (-10)
end
end
The sprite can go faster or slower by changing the amounts.
- Lachiepower0402
-
New Scratcher
7 posts
How to make Sprites Move Smoothly
Thanks that works perfectly, but I have another question. In this same game the car passes brick walls that are moving past the car, how can I make it so that when the car misses a brick wall their is a score that shows this?
- AonymousGuy
-
Scratcher
1000+ posts
How to make Sprites Move Smoothly
It depends on how the walls are moving. Is the car sprite staying in the center of the screen, with the wall sprites moving? If so, then you can do something like this:
Also, if this isn't the method your game is using, please say so, as I can give a more helpful script. It will probably be somewhat similar to this script anyways.
when gf clicked //In the car spriteVariable explanation: If you don't yet know what a variable is, you can create one by going to the Data tab and clicking “Create Variable”, then naming it what you want (in this case, Score.) Variables are basically just values that can be rewritten and reused, so their value will be read and used instead of a manually input value. (If that makes sense.)
set [Score v] to [0]//This is a variable. If you don't know what this is, refer to bottom section.
forever
if <([x position v] of [brick_wall v]) < (x position)> then
change [Score v] by (1)
end
end
Also, if this isn't the method your game is using, please say so, as I can give a more helpful script. It will probably be somewhat similar to this script anyways.

- Lachiepower0402
-
New Scratcher
7 posts
How to make Sprites Move Smoothly
No sorry that didn't work, the car sprite moves left and right along the screen and a wall comes down from the top of the screen to the bottom, hides, reappers at the top in a different spot and goes down again and the car has to avoid the wall otherwise a background comes up saying game over. So for every wall the car doesn't hit I want the score to go up by one. What happened just then was when I avoided a wall the score when up very quickly to a high number i.e. 17931724.
- AonymousGuy
-
Scratcher
1000+ posts
How to make Sprites Move Smoothly
No sorry that didn't work, the car sprite moves left and right along the screen and a wall comes down from the top of the screen to the bottom, hides, reappers at the top in a different spot and goes down again and the car has to avoid the wall otherwise a background comes up saying game over. So for every wall the car doesn't hit I want the score to go up by one. What happened just then was when I avoided a wall the score when up very quickly to a high number i.e. 17931724.Okay, so I think that means that the x position blocks just have to be changed to y position blocks:
when gf clicked //In the car sprite
set [Score v] to [0]//This is a variable. If you don't know what this is, refer to bottom section.
forever
if <([y position v] of [brick_wall v]) < (y position)> then
change [Score v] by (1)
end
end
- Lachiepower0402
-
New Scratcher
7 posts
How to make Sprites Move Smoothly
That is a lot better, but the score doesn't just go up by 1, when the wall passes the car the scores goes up until the wall disappears, so the wall moves from the top goes down and passes the car as i avoid it and the score goes up when moving past the car and then the wall moves to the top again.
- AonymousGuy
-
Scratcher
1000+ posts
How to make Sprites Move Smoothly
Add the following after the block changing the score:
wait until <not <([y position v] of [brick_wall v]) < (y position)>>
- AonymousGuy
-
Scratcher
1000+ posts
How to make Sprites Move Smoothly
That works, thank you.You're welcome!

- lederniersamourai
-
Scratcher
500+ posts
How to make Sprites Move Smoothly
glide can be interrupted any time: just put them under an “event hat” such as this one:I just use the glide __ seconds to x:__ y:__, but that’s just because I do animations. If you are doing a game it would be harder.
Glides are great for somethings.
I don't like them for games though because once you start a glide you pretty much have to finish it.
when I receive [glide1 v]Just set variable to new values to glide on another path and schedule, and then use neutral values (i.e. 0 secs, current x value and current y value) for stopping gliding,
glide (sec var) secs to x: (x var) y: (y var)
- Cyoce
-
Scratcher
500+ posts
How to make Sprites Move Smoothly
when green flag clicked
forever
set [X v] to (where you want the sprite's X to be)
set [Y v] to (where you want the sprite's Y to be)
if <something causes it to stop the glide> then
set [X v] to (x position)
set [Y v] to (y position)
else
change x by (((X) - (x position)) * ([abs v] of (((X) - (x position)) / ([abs v] of (((X) - (x position)) + ([abs v] of ((Y) - (Y position)
change y by (((Y) - (y position)) * ([abs v] of (((Y) - (Y position)) / ([abs v] of (((X) - (x position)) + ([abs v] of ((Y) - (Y position)
end
- -appletree-
-
Scratcher
43 posts
How to make Sprites Move Smoothly
when green flag clicked
forever
if <key [right arrow v] pressed?> then
change x by (4)
end
end
- REPUS
-
Scratcher
18 posts
How to make Sprites Move Smoothly
This script will make a sprite glide to a place ten steps over, instead of simply reappearing in a place ten steps over.
when [ Left arrow] key pressed
glide (0.3) secs to x: ((-10) + (x position)) y: (y position)
when [ Right arrow] key pressed
glide (0.3) secs to x: ((10) + (x position)) y: (y position)
Last edited by REPUS (Nov. 11, 2014 02:52:04)
- Discussion Forums
- » Help with Scripts
-
» How to make Sprites Move Smoothly

