Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » How exactly does the "if on edge, bounce" block work
- The2AndOnly
-
Scratcher
88 posts
How exactly does the "if on edge, bounce" block work
I tried copying it but it didn't work. How do you replicate it perfectly so you can use it on other sprites, or how is it written is the actual scratch code. (java script I think)
- RL1123
-
Scratcher
1000+ posts
How exactly does the "if on edge, bounce" block work

The image above is a geometrical representation of what happens. If you don't know enough math to understand it, basically, the angle of the sprite hitting the edge is the same as the angle when facing away. So basically, you need to get the angle the cat is from the edge and turn so that the election is also that many degrees. This person made a nice custom way of if on edge, bounce.
Last edited by RL1123 (Feb. 3, 2022 23:40:02)
- The2AndOnly
-
Scratcher
88 posts
How exactly does the "if on edge, bounce" block work
Ye I know that but the sprite always gets stuck inside the edge so how does it get pushed out or how does it avoid getting stuck
The image above is a geometrical representation of what happens. If you don't know enough math to understand it, basically, the angle of the sprite hitting the edge is the same as the angle when facing away. So basically, you need to get the angle the cat is from the edge and turn so that the election is also that many degrees. This person made a nice custom way of if on edge, bounce.
- DinoMaster20
-
Scratcher
1000+ posts
How exactly does the "if on edge, bounce" block work
Usually, people actually have to use more code than that one block alone. I'm just bad at coding, so I couldn't help with thatYe I know that but the sprite always gets stuck inside the edge so how does it get pushed out or how does it avoid getting stuck
The image above is a geometrical representation of what happens. If you don't know enough math to understand it, basically, the angle of the sprite hitting the edge is the same as the angle when facing away. So basically, you need to get the angle the cat is from the edge and turn so that the election is also that many degrees. This person made a nice custom way of if on edge, bounce.
- RL1123
-
Scratcher
1000+ posts
How exactly does the "if on edge, bounce" block work
Usually, people actually have to use more code than that one block alone. I'm just bad at coding, so I couldn't help with thatIt would be much more helpful if you stated what code to use instead of stating the obvious.
Ye I know that but the sprite always gets stuck inside the edge so how does it get pushed out or how does it avoid getting stuckMaybe
// The custom block should be run without screen refreshThis will force your sprite out of the edge.
define Move out of edge
repeat until <not <touching [edge v] ?>>
move (-1) steps
end
Last edited by RL1123 (Feb. 4, 2022 01:00:05)
- The2AndOnly
-
Scratcher
88 posts
How exactly does the "if on edge, bounce" block work
I tried that but then sometimes it still gets stuck inside of the edge and it freezes the programYe I know that but the sprite always gets stuck inside the edge so how does it get pushed out or how does it avoid getting stuckMaybe// The custom block should be run without screen refreshThis will force your sprite out of the edge.
define Move out of edge
repeat until <not <touching [edge v] ?>>
move (-1) steps
end
- RL1123
-
Scratcher
1000+ posts
How exactly does the "if on edge, bounce" block work
Then can you send the project that you're working on?
- Discussion Forums
- » Questions about Scratch
-
» How exactly does the "if on edge, bounce" block work


