Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Movement and shooting
- gt2468
-
Scratcher
5 posts
Movement and shooting
So for some reason, when I code some simple movement for arrow keys and shooting with if blocks, when I shoot and move up and right diagonally, It doesn't shoot or move diagonally.
Movement eg:
Shooting eg:
Movement eg:
if <key [left arrow] pressed?> then
change x by (-10)
end
if <key [up arrow] pressed?> then
change y by (10)
end
if <key [right arrow] pressed?> then
change x by (10)
end
if <key [down arrow] pressed?> then
change y by (-10)
end
Shooting eg:
if <key [a] pressed?> then
create clone of [ myself]
end
when I start as a clone
repeat until <touching [ edge] ?>
move (10) steps
end
delete this clone
Last edited by gt2468 (May 27, 2024 11:07:19)
- mewercats
-
Scratcher
100+ posts
Movement and shooting
Reported to Help with Scripts. This place is not where you put topics like these. 

- cosmosaura
-
Scratch Team
1000+ posts
Movement and shooting
I'll move this over to the Help with Scripts section for you - that's a better fit for this kind of topic 

- Jlerpy
-
Scratcher
1000+ posts
Movement and shooting
If I correspond left to x -10, right to x +10, up to y +10 and down to y -10, the sprite moves pretty smoothly diagonally.
Making your projectiles clones of the main sprite will mean that they'll face the same direction the main sprite is, and head that way. You don't currently have the main sprite changing facing at all though.
Making your projectiles clones of the main sprite will mean that they'll face the same direction the main sprite is, and head that way. You don't currently have the main sprite changing facing at all though.
- gt2468
-
Scratcher
5 posts
Movement and shooting
The code is for this: https://scratch.mit.edu/projects/722655363/
I used the code for a 2 player game and it works for player 1, but not player 2
I used the code for a 2 player game and it works for player 1, but not player 2
Last edited by gt2468 (May 27, 2024 10:59:11)
- gt2468
-
Scratcher
5 posts
Movement and shooting
Nevermind, I fixed the glitch
So, the glitch was that when I moved diagonally and I was shooting with the n key, the code would stop moving diagonally or stop shooting.
I changed the n key to the j key.
So, the glitch was that when I moved diagonally and I was shooting with the n key, the code would stop moving diagonally or stop shooting.
I changed the n key to the j key.
Last edited by gt2468 (May 27, 2024 11:16:39)
- Discussion Forums
- » Help with Scripts
-
» Movement and shooting