Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Character moving foreward and backwards
- inkuhana
-
New Scratcher
5 posts
Character moving foreward and backwards
Testing out some movement on a scratch game. The setting is 2D and the character can move left and right, however I want them to move back and foreward using the up and down keys. To achieve this, I use the size and layer functions. However, I want this to work with the enviroment so that when you press up to move back, the character can move behind an object it was previously in front or vice versa.
The size does work, the character will increase and decrease in size to the button press. Unfortunately, the layer system will not. I cannot get the character to move 1 layer up with the press- yes, it will only take one layer I pressed the command in the code section to make sure.
My code looks like this:
The sprite's default size is 100. I'd also like a limit to how much they can move foreward and back if that's possible. I'm not sure how to make it limited.
Thank you to anyone who can help.
The size does work, the character will increase and decrease in size to the button press. Unfortunately, the layer system will not. I cannot get the character to move 1 layer up with the press- yes, it will only take one layer I pressed the command in the code section to make sure.
My code looks like this:
when [ down arrow] key pressed
if <(size) = [105]> then
go foreward (1) layers
end
The sprite's default size is 100. I'd also like a limit to how much they can move foreward and back if that's possible. I'm not sure how to make it limited.
Thank you to anyone who can help.
- legendary34678
-
Scratcher
1000+ posts
Character moving foreward and backwards
Can you please post the link to your project? Thanks!
- inkuhana
-
New Scratcher
5 posts
Character moving foreward and backwards
Can you please post the link to your project? Thanks!
It's not done so I have it private but I'll post it real quick so you can check it out to help! https://scratch.mit.edu/projects/839569333/
- medians
-
Scratcher
1000+ posts
Character moving foreward and backwards
Did you set the size to 105 at any point though?
And I think you mean this:
And I think you mean this:
when [down arrow v] key pressedYou’d probably have to keep track of how many layers you have gone forward with a variable.
if <(size) = [105]> then
go back (-1) layers
end
Last edited by medians (April 24, 2023 05:36:28)
- Link2358
-
Scratcher
100+ posts
Character moving foreward and backwards
You may be able to use a script similar to griffpatch's 3D sprite layering tutorial, but with size instead.
- inkuhana
-
New Scratcher
5 posts
Character moving foreward and backwards
Did you set the size to 105 at any point though?
And I think you mean this:when [down arrow v] key pressedYou’d probably have to keep track of how many layers you have gone forward with a variable.
if <(size) = [105]> then
go back (-1) layers
end
oops I just noticed I wrote 105 instead of 102 in my original post!
I thought that clicking the button twice would move the size up to 102 right? So it wouldn't need to be set. Thank you for the advice though! I never considered keeping track of the layers via variable- that would make stuff so much easier.
- Discussion Forums
- » Help with Scripts
-
» Character moving foreward and backwards



