Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Changing costumes based on direction
- icon96
- New to Scratch
4 posts
Changing costumes based on direction
I'm trying to have the Tasmanian devil chase the bunny and change costumes depending on where the bunny is located, but it keeps switching to the wrong costume, anyone know what I'm doing wrong?
The link to my project:
Your text to link here…
The link to my project:
Your text to link here…
- povthebox
- New to Scratch
8 posts
Changing costumes based on direction
your code is really unorganized right now, organize it and i may help you
g̡̙̟͖͙͎̈́̿̀e̝͙͔̦̘̻̓̿̽ț͓̦̞͖̓̓͝ t͙̠͕̝͛̈́͛͜r̠͍͙̔̿͜o̟͔͙̟̝̦͊̈́̚l̢͚͚̻̀̾͒͜͜l̻͚͎͎͔̒̽̽ë̡̼̺͙́̿͘͜͜d͎͖͔̟̫͊̒̚͜ ╚(̠͕͎̺̟͚̞̞̻͌̈́̈́̾͊͛̚̚•̪̼͇̼͎͉̼̘͊̓̓̓̽͒͒͌̕⌂̡̝̞̼͓͔͔̝͋͊͆͐̓̀͋͐̚͜•̝̠̫̺͓̺͍̼͌̓͑̈́͊͘͘͘͘)͇͔̠͙͖̠̺͔̪̓̀͆͌̈́͑́͠͝╝
please don't talk to me back on discussion posts because i dont follow them.
tell me on my profile thanks, in the “Forum Replies” section.
- deck26
- Scratcher
1000+ posts
Changing costumes based on direction
The problem or the organisation of the project? fixed it
- RT_Borg
- Scratcher
1000+ posts
Changing costumes based on direction
Hi icon96, Welcome to Scratch!
It looks like you've mostly got your costumes switching when you want now. Congratulations!
If you want the most precise direction numbers for when you should switch, change +/- 55 to +/- 45, and change +/- 120 to +/- 135.
(In math, the angle between horizontal and vertical is 90 degrees. The 45 degrees I'm suggesting comes from 1/2 that 90 degrees. Then to rotate a 1/4 of a circle, it's 45 + 90 = 135. Similar angles for the - values going counter-clockwise.)
Also, this is a great place to learn an important lesson about animations in scratch. That is, it's always good to separate your movement code and your animation code into 2 different sprites.
What's happening every time through your loop is:
But when the animation runs, it picks the right direction and does costume changes with pauses between each costume. These pauses are necessary to make the timing on the animation look right.
So that means in step 1, we pause for about 1/3 of a second to do a few costume changes.
Meanwhile, we can't move (for that 1/3) of a second.
Instead, we can have 2 scripts:
Script 1
Script 2
Then Script 1 can move without being paused by whatever waits you need for the animation loop. It ends up looking like:
Happy to answer any questions,
– RT_Borg
It looks like you've mostly got your costumes switching when you want now. Congratulations!
If you want the most precise direction numbers for when you should switch, change +/- 55 to +/- 45, and change +/- 120 to +/- 135.
(In math, the angle between horizontal and vertical is 90 degrees. The 45 degrees I'm suggesting comes from 1/2 that 90 degrees. Then to rotate a 1/4 of a circle, it's 45 + 90 = 135. Similar angles for the - values going counter-clockwise.)
Also, this is a great place to learn an important lesson about animations in scratch. That is, it's always good to separate your movement code and your animation code into 2 different sprites.
What's happening every time through your loop is:
- follow (animation runs)
- point toward bunny
- move 1 step
But when the animation runs, it picks the right direction and does costume changes with pauses between each costume. These pauses are necessary to make the timing on the animation look right.
So that means in step 1, we pause for about 1/3 of a second to do a few costume changes.
Meanwhile, we can't move (for that 1/3) of a second.
Instead, we can have 2 scripts:
Script 1
- point toward bunny
- move 1 step
- maybe put a short wait if it's moving too fast
Script 2
- follow (animation runs)
Then Script 1 can move without being paused by whatever waits you need for the animation loop. It ends up looking like:
when @greenFlag clicked
forever
point towards [bunny v]
move (1) steps // If taz is moving too slow, move more than 1
... // if taz is moving too fast, put a short wait.
end
when @greenFlag clicked
forever
follow::custom
end
define follow
if <<(direction) \< [-45]> and <(direction) \> [-135]>> then
switch costume to [taz left walk v]
wait (.1) secs
switch costume to [taz left walk2 v]
wait (.1) secs
switch costume to [taz left walk3 v]
wait (.1) secs
switch costume to [taz left walk4 v]
wait (.1) secs // you're missing one wait on each animation loop
end
if <<(direction) \> [-45]> and <(direction) \< [45]>> then
switch costume to [taz up walk v]
wait (.1) secs
switch costume to [taz up walk2 v]
wait (.1) secs
switch costume to [taz up walk3 v]
wait (.1) secs
switch costume to [taz up walk4 v]
wait (.1) secs // you're missing one wait on each animation loop
end
if <<(direction) \< [135]> and <(direction) \> [45]>> then
switch costume to [taz right walk v]
wait (.1) secs
switch costume to [taz right walk2 v]
wait (.1) secs
switch costume to [taz right walk3 v]
wait (.1) secs
switch costume to [taz down walk4 v]
wait (.1) secs // you're missing one wait on each animation loop
end
if <<(direction) \> [135]> or <(direction) \< [-135]>> then
switch costume to [taz down walk v]
wait (.1) secs
switch costume to [taz down walk2 v]
wait (.1) secs
switch costume to [taz down walk3 v]
wait (.1) secs
switch costume to [taz down walk4 v]
wait (.1) secs // you're missing one wait on each animation loop
end
Happy to answer any questions,
– RT_Borg
- icon96
- New to Scratch
4 posts
Changing costumes based on direction
Thanks a lot for the thorough explanation RT_Borg.
- ProtoBIT_09
- Scratcher
17 posts
Changing costumes based on direction
I'm trying to make a platformer and I don't know how to make the player switch to a different costume based on direction
You can call me Daan.
- SpyCoderX
- Scratcher
100+ posts
Changing costumes based on direction
Please make a new topic. Thanks! I'm trying to make a platformer and I don't know how to make the player switch to a different costume based on direction
New game! (link)
Have a good day/night!
\(-_-) ::#00AAAA //This is crypto. He protects my signature from the evil kumquats!Programming is a very powerful skill. As are critical thinking and hard work.
- SpyCoderX
- Gateway_Dragon56real
- Scratcher
6 posts
Changing costumes based on direction
You should make a block of skip sounds to a different one if you're in Pennsylvania hope the solar eclipse goes well for you to
- Discussion Forums
- » Help with Scripts
- » Changing costumes based on direction