Discuss Scratch

ducky3624
Scratcher
22 posts

How do you make sprites move in the direction up, down, left and right etc????????

I wanna move up , down, left and right in scratch, but HOW!
Here's what I did for up;

when [ up] key pressed
point in direction ( 90)
move (10) steps




but it didn't work!

Last edited by ducky3624 (March 20, 2024 22:14:45)

MineTurte
Scratcher
1000+ posts

How do you make sprites move in the direction up, down, left and right etc????????

ducky3624 wrote:

I wanna move up , down, left and right in scratch, but HOW!
Here's what I did for up;

when [ up] key pressed
point in direction ( 90)
move (10) steps



but it didn't work!
Here's how:

when [ up arrow] key pressed
change y by (10)

when [ down arrow] key pressed
change y by (-10)

when [ left arrow] key pressed
change x by (-10)

when [ right arrow] key pressed
change x by (10)

Hope this helps!
Intelligent684
Scratcher
100+ posts

How do you make sprites move in the direction up, down, left and right etc????????

Something more responsive you can try, is this: (For this code, you can hold down movement keys.)
when green flag clicked
forever
if <key [up arrow v] pressed?> then
change y by (10)
end
if <key [down arrow v] pressed?> then
change y by (-10)
end
end

Copy this for left and right (as mineturte said, left is -10x, right is 10x.)

Last edited by Intelligent684 (March 21, 2024 13:20:17)

ducky3624
Scratcher
22 posts

How do you make sprites move in the direction up, down, left and right etc????????

Intelligent684 wrote:

Something more responsive you can try, is this: (For this code, you can hold down movement keys.)
when green flag clicked
forever
if <key [up arrow v] pressed?> then
change y by (10)
end
if <key [down arrow v] pressed?> then
change y by (-10)
end
end

Copy this for left and right (as mineturte said, left is -10x, right is 10x.)


Good, but a bit too complicated
ducky3624
Scratcher
22 posts

How do you make sprites move in the direction up, down, left and right etc????????

MineTurte wrote:

ducky3624 wrote:

I wanna move up , down, left and right in scratch, but HOW!
Here's what I did for up;

when [ up] key pressed
point in direction ( 90)
move (10) steps



but it didn't work!
Here's how:

when [ up arrow] key pressed
change y by (10)

when [ down arrow] key pressed
change y by (-10)

when [ left arrow] key pressed
change x by (-10)

when [ right arrow] key pressed
change x by (10)

Hope this helps!



Cool! I'll try then say if it worked or not!
thanks!
ztsereteli
Scratcher
91 posts

How do you make sprites move in the direction up, down, left and right etc????????

ducky3624 wrote:

Intelligent684 wrote:

Something more responsive you can try, is this: (For this code, you can hold down movement keys.)
when green flag clicked
forever
if <key [up arrow v] pressed?> then
change y by (10)
end
if <key [down arrow v] pressed?> then
change y by (-10)
end
end

Copy this for left and right (as mineturte said, left is -10x, right is 10x.)


Good, but a bit too complicated

No, you should definitely use this version. It looks like a complicated version of the same thing, but it feels 10x smoother! Instead of the snappy, unresponsive movement, this one lets you hold the keys down without a wait.
MrKingofScratch
Scratcher
100+ posts

How do you make sprites move in the direction up, down, left and right etc????????

If you want to use your old code it would be

when [up arrow v] key pressed
point in direction (0 v)
move (10) steps

when [down arrow v] key pressed
point in direction (180 v)
move (10) steps

when [right arrow v] key pressed
point in direction (90 v)
move (10) steps

when [left arrow v] key pressed
point in direction (-90 v)
move (10) steps

The 90 in the point in direction block refers to the direction in degrees that the sprite faces. Move 10 steps moves the sprite 10 units in that direction.

However, this code would make it so that holding the key works better:

when [up arrow v] key pressed
point in direction (0 v)
repeat until <not <key [up arrow v] pressed?>>
move (10) steps
end

when [down arrow v] key pressed
point in direction (180 v)
repeat until <not <key [down arrow v] pressed?>>
move (10) steps
end

when [right arrow v] key pressed
point in direction (90 v)
repeat until <not <key [right arrow v] pressed?>>
move (10) steps
end

try to figure out the code for moving left by yourself! (Hint: it follows the same pattern as movement for the other directions)

Last edited by MrKingofScratch (March 27, 2024 06:17:01)

qwertycodechamp90411
Scratcher
100+ posts

How do you make sprites move in the direction up, down, left and right etc????????

Intelligent684 wrote:

Something more responsive you can try, is this: (For this code, you can hold down movement keys.)
when green flag clicked
forever // so you can click it whenever
if <key [up arrow v] pressed?> then
change y by (10) // if the up arrow is pressed, go up 10
end
if <key [down arrow v] pressed?> then
change y by (-10) // go up -10 = go down 10
end
end

Copy this for left and right (as mineturte said, left is -10x, right is 10x.)
Added explanation

Powered by DjangoBB