Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Code for smoother walking
- K4ffekoppen
-
New Scratcher
44 posts
Code for smoother walking
Hey all.
At the moment the code that I made for my character while walking is this;
And the same for up, down and right, now this works but it's a bit choppy as you can see and I want it to be smoother, I would like to have the movement of link in this project (or similar);
https://scratch.mit.edu/projects/446028518/
But eventhough I can see the code there I can't really understand how we got the movement, he has around 16 costumes total for his character and I'm not looking to have the same amount, so I don't need to have the same visual as he does but yea the movement.
Appreciate any help with this, thanks.
/K4ffekoppen
At the moment the code that I made for my character while walking is this;
when [a v] key pressed
repeat (2)
switch costume to [Alestarion left1 v]
change x by (-7)
wait (0.1) secs
switch costume to [Alestarion left2 v]
change x by (-7)
wait (0.1) secs
end
And the same for up, down and right, now this works but it's a bit choppy as you can see and I want it to be smoother, I would like to have the movement of link in this project (or similar);
https://scratch.mit.edu/projects/446028518/
But eventhough I can see the code there I can't really understand how we got the movement, he has around 16 costumes total for his character and I'm not looking to have the same amount, so I don't need to have the same visual as he does but yea the movement.
Appreciate any help with this, thanks.
/K4ffekoppen
- dragonsnake003
-
Scratcher
100+ posts
Code for smoother walking
Hey all.
At the moment the code that I made for my character while walking is this;when [a v] key pressed
repeat (2)
switch costume to [Alestarion left1 v]
change x by (-7)
wait (0.1) secs
switch costume to [Alestarion left2 v]
change x by (-7)
wait (0.1) secs
end
And the same for up, down and right, now this works but it's a bit choppy as you can see and I want it to be smoother, I would like to have the movement of link in this project (or similar);
https://scratch.mit.edu/projects/446028518/
But eventhough I can see the code there I can't really understand how we got the movement, he has around 16 costumes total for his character and I'm not looking to have the same amount, so I don't need to have the same visual as he does but yea the movement.
Appreciate any help with this, thanks.
/K4ffekoppen
when green flag clicked
forever
if <key [ v] pressed?> then
change x by (5)
end
end
Add this same if statement in the forever loop for each key.
Last edited by dragonsnake003 (Nov. 2, 2024 21:26:32)
- K4ffekoppen
-
New Scratcher
44 posts
Code for smoother walking
when green flag clicked
forever
if <key [ v] pressed?> then
change x by (5)
end
end
Add this same if statement in the forever loop for each key.
What, that just makes the player slide 5 steps forever?
- Oisthebestletter
-
Scratcher
100+ posts
Code for smoother walking
I would recommend not having a wait block.
- UnscrambledEgg
-
Scratcher
100+ posts
Code for smoother walking
Hey all.You should make 2 seperate functions: one for walking and another for the animation. The animation should repeat until the key is not pressed anymore.
At the moment the code that I made for my character while walking is this;when [a v] key pressed
repeat (2)
switch costume to [Alestarion left1 v]
change x by (-7)
wait (0.1) secs
switch costume to [Alestarion left2 v]
change x by (-7)
wait (0.1) secs
end
And the same for up, down and right, now this works but it's a bit choppy as you can see and I want it to be smoother, I would like to have the movement of link in this project (or similar);
https://scratch.mit.edu/projects/446028518/
But eventhough I can see the code there I can't really understand how we got the movement, he has around 16 costumes total for his character and I'm not looking to have the same amount, so I don't need to have the same visual as he does but yea the movement.
Appreciate any help with this, thanks.
/K4ffekoppen
- K4ffekoppen
-
New Scratcher
44 posts
Code for smoother walking
I would recommend not having a wait block.´
If I don't have a wait block the character doesn't switch between the costumes, just the same one, so that's why I added the 0.1 sec wait.
- K4ffekoppen
-
New Scratcher
44 posts
Code for smoother walking
You should make 2 seperate functions: one for walking and another for the animation. The animation should repeat until the key is not pressed anymore.
I tried that but actually it worked better even with just adding that ‘until key is not pressed anymore’ but keeping the rest, so it's smoother now.
I'm not sure why you want to seperate the animation and walking but is there a reason for that?
So now I did this and it's working quite well I think.
when [a v] key pressed
repeat until <not <key [a v] pressed?>>
switch costume to [Wizard1 left v]
change x by (-5)
wait (0.1) secs
switch costume to [Wizard1 left2 v]
change x by (-5)
wait (0.1) secs
end
- ametrine_
-
Scratcher
1000+ posts
Code for smoother walking
What, that just makes the player slide 5 steps forever?it doesn't, it only moves if the key is being pressed. it *would* move forever if it was this, though:
if <key [ v] pressed?> then
forever
change x by (5)
end
end
- K4ffekoppen
-
New Scratcher
44 posts
Code for smoother walking
What, that just makes the player slide 5 steps forever?it doesn't, it only moves if the key is being pressed. it *would* move forever if it was this, though:if <key [ v] pressed?> then
forever
change x by (5)
end
end
True I still had the “When key a pressed” instead of green flag so that's why it just kept going I think.
But still, without the added pauses this just slides so you can't see the animations.
- ametrine_
-
Scratcher
1000+ posts
Code for smoother walking
But still, without the added pauses this just slides so you can't see the animations.which is why you need a separate script for the animations running at the same time (like @UnscrambledEgg talked about)
- K4ffekoppen
-
New Scratcher
44 posts
Code for smoother walking
which is why you need a separate script for the animations running at the same time (like @UnscrambledEgg talked about)
Okey but is that better than just doing the latest code I used now?
when [a v] key pressed
repeat until <not <key [a v] pressed?>>
switch costume to [Wizard1 left v]
change x by (-5)
wait (0.1) secs
switch costume to [Wizard1 left2 v]
change x by (-5)
wait (0.1) secs
end
So with the two seperated ones it would be like this?
when green flag clickedAnd then also
forever
if <key [a v] pressed?> then
change x by (-5)
end
end
when green flag clicked
forever
if <key [a v] pressed?> then
switch costume to [Wizard1 left v]
wait (0.1) secs
switch costume to [Wizard1 left2 v]
wait (0.1) secs
end
Would that be what you mean?
- Oisthebestletter
-
Scratcher
100+ posts
Code for smoother walking
Perfect!!!which is why you need a separate script for the animations running at the same time (like @UnscrambledEgg talked about)
Okey but is that better than just doing the latest code I used now?when [a v] key pressed
repeat until <not <key [a v] pressed?>>
switch costume to [Wizard1 left v]
change x by (-5)
wait (0.1) secs
switch costume to [Wizard1 left2 v]
change x by (-5)
wait (0.1) secs
end
So with the two seperated ones it would be like this?when green flag clickedAnd then also
forever
if <key [a v] pressed?> then
change x by (-5)
end
endwhen green flag clicked
forever
if <key [a v] pressed?> then
switch costume to [Wizard1 left v]
wait (0.1) secs
switch costume to [Wizard1 left2 v]
wait (0.1) secs
end
Would that be what you mean?
- star_clicker
-
Scratcher
1 post
Code for smoother walking
how would I design a 8-bit charter and make them walk?
Last edited by star_clicker (Oct. 28, 2025 14:29:58)
- Discussion Forums
- » Help with Scripts
-
» Code for smoother walking





