Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make your sprite move left and right
- joshly50
-
Scratcher
81 posts
How to make your sprite move left and right
To make your sprite move left and right follow this script
To move right
Go to events and drag block called (When space key pressed) change it to (When right arrow key pressed)
Then go to motion and drag move 10 steps and change it to 30 and snap the blocks together.
To move left
Go to events and drag block called (When space key pressed) change it to (When left arrow key pressed)
Then go to motion and drag move 10 steps and change it to -30 and snap the blocks together.
To move right
Go to events and drag block called (When space key pressed) change it to (When right arrow key pressed)
Then go to motion and drag move 10 steps and change it to 30 and snap the blocks together.
To move left
Go to events and drag block called (When space key pressed) change it to (When left arrow key pressed)
Then go to motion and drag move 10 steps and change it to -30 and snap the blocks together.
- andre_rifaut_tests
-
Scratcher
90 posts
How to make your sprite move left and right
This is correct.
But you can add some fun.
For instance just try with the cat:
The cat will move 30 steps but you will see it move its feet.
But you can add some fun.
For instance just try with the cat:
when [right arrow v] key pressed
repeat (10)
move (3) steps
next costume
end
The cat will move 30 steps but you will see it move its feet.
- KermitMC
-
Scratcher
100+ posts
How to make your sprite move left and right
This is correct.There is a much better way than that.
But you can add some fun.
For instance just try with the cat:when [right arrow v] key pressed
repeat (10)
move (3) steps
next costume
end
The cat will move 30 steps but you will see it move its feet.
when gf clicked
forever
if <key pressed [left v]>
change x by (-5)
next costume
end
if <key pressed [right v]>
change x by (5)
next costume
end
end
Hope this helps
Last edited by KermitMC (Nov. 30, 2013 15:12:11)
- GadgetAndyMan
-
Scratcher
100+ posts
How to make your sprite move left and right
Yes the if key pressed option allows for a faster response. If that isn't needed or not suitable for your project, then the when key pressed block does the job.
- lolman67
-
Scratcher
6 posts
How to make your sprite move left and right
when [arow[quote=KermitMC][quote=andre_rifaut_tests]This is correct.
But you can add some fun.
For instance just try with the cat:
[scratchblocks]
when [right arrow v] key pressed
repeat (10)
move (3) steps
next costume
end
[/scratchblocks]
The cat will move 30 steps but you will see it move its feet.[/quote]
There is a much better way than that.
[scratchblocks]
when gf clicked
forever
if <key pressed [left v]>
change x by (-5)
next costume
end
if <key pressed [right v]>
change x by (5)
next costume
end
end
[/scratchblocks]
Hope this helps[/quote]
v] key pressed
move (10) steps
- digthebone
-
Scratcher
500+ posts
How to make your sprite move left and right
when green flag clicked
forever
if <key [left arrow v] pressed?> then
set [moving direction v] to [left]
if <key [right arrow v] pressed?> then
set [moving direction v] to [right]
end
end
end
when green flag clicked
forever
if <(moving direction) = [right]> then
change x by (5)
if <(moving direction) = [left]> then
change x by (-5)
end
end
end
hopefully that helped

and always remember
when green flag clicked
forever
if <got help from digthebone.> then
know he is awesome
end
end

- digthebone
-
Scratcher
500+ posts
How to make your sprite move left and right
when green flag clicked
forever
if <key [left arrow v] pressed?> then
set [moving direction v] to [left]
if <key [right arrow v] pressed?> then
set [moving direction v] to [right]
end
end
end
when green flag clicked
forever
if <(moving direction) = [right]> then
change x by (5)
if <(moving direction) = [left]> then
change x by (-5)
end
if <(moving direction) = [left]> then
change x by (-5)
end
end
hopefully that helped
and always rememberwhen green flag clicked
forever
if <got help from digthebone.> then
know he is awesome
end
end
- turkey3
-
Scratcher
1000+ posts
How to make your sprite move left and right
Those could be combined into one, more efficient script.when green flag clicked
forever
if <key [left arrow v] pressed?> then
set [moving direction v] to [left]
if <key [right arrow v] pressed?> then
set [moving direction v] to [right]
end
end
end
when green flag clicked
forever
if <(moving direction) = [right]> then
change x by (5)
if <(moving direction) = [left]> then
change x by (-5)
end
end
end
hopefully that helped
and always rememberwhen green flag clicked]
forever
if <got help from digthebone.> then
know he is awesome
end
end
- Scratching_Vornado
-
Scratcher
14 posts
How to make your sprite move left and right
Using
isn't very good as it doesn't work very well. Sometimes it moves once, stops, then moves forward again. As other people said, you should do something like this:
Maybe through in a
in there.
move () steps
isn't very good as it doesn't work very well. Sometimes it moves once, stops, then moves forward again. As other people said, you should do something like this:
when green flag clicked
forever
if <key [right arrow v] pressed?> then
change x by (30)
end
if <key [left arrow v] pressed?> then
change x by (-30)
end
end
Maybe through in a
wait (0.01) secs
in there.
- typemaster
-
Scratcher
100+ posts
How to make your sprite move left and right
X and Y are the coordinates of the location of the sprite as you probably already know.
Here is the most efficient way to make a sprite move left and right:
Hope I helped you!
You will find that most of my projects use those scripts that I gave you.
Here is the most efficient way to make a sprite move left and right:
when [right arrow] key pressed
change x by (5)
//this is for moving right
when [left arrow] key pressed
change x by (-5)
//this is the script for moving left
Hope I helped you!
You will find that most of my projects use those scripts that I gave you.
- csonic6
-
Scratcher
4 posts
How to make your sprite move left and right
Like this!
when [-->] key pressedmove (10) steps
- r123a
-
Scratcher
1000+ posts
How to make your sprite move left and right
when [left] key pressed
end
change x by (-10)
end
- Nyan_Banana
-
Scratcher
14 posts
How to make your sprite move left and right
You just need When Flag Clicked change x by (how ever much you want). If you want it to go left make it a minus number
Last edited by Nyan_Banana (March 17, 2015 13:46:36)
- blazingames
-
Scratcher
22 posts
How to make your sprite move left and right
We all know how.
when [right key v] key pressed
move (1) steps
- Starvia
-
Scratcher
17 posts
How to make your sprite move left and right
How do you make scratchblocks?
- GyroscopeBill
-
Scratcher
500+ posts
How to make your sprite move left and right
How do you make scratchblocks?When you make a post, look at the icons above the bit where you type. One of those is a small blue block with a down arrow next to it. Click on there and you can then click on the blocks. Alternatively, you can do what I do and type them manually.
Happy (scratchblocks :: operators) :: motion
- minecrafternotch
-
Scratcher
3 posts
How to make your sprite move left and right
In the latest version of scratch it's easy.Two ways are with a mouse,and by arrow keys
Mouse
Arrows:
end
Mouse
when this sprite clicked
glide (1) secs to x: (mouse x) y: (mouse y)
Arrows:
when [right arrow] key pressed
repeat until <touching [other block] ?>
move (3) steps
end
when I receive [Fame and Glory]
go to [The moon and live life]
- gaoj5892
-
Scratcher
3 posts
How to make your sprite move left and right
when green flag clicked
forever
if <key [ left arrow] pressed?> then
move (5) steps
end
end
- Discussion Forums
- » Help with Scripts
-
» How to make your sprite move left and right

















