Discuss Scratch

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

rayli1123 wrote:


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.
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
DinoMaster20
Scratcher
1000+ posts

How exactly does the "if on edge, bounce" block work

The2AndOnly wrote:

rayli1123 wrote:


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.
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
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 that
RL1123
Scratcher
1000+ posts

How exactly does the "if on edge, bounce" block work

DinoMaster20 wrote:

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 that
It would be much more helpful if you stated what code to use instead of stating the obvious.

The2AndOnly wrote:

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
Maybe
// The custom block should be run without screen refresh
define Move out of edge
repeat until <not <touching [edge v] ?>>
move (-1) steps
end
This will force your sprite out of the edge.

Last edited by RL1123 (Feb. 4, 2022 01:00:05)

The2AndOnly
Scratcher
88 posts

How exactly does the "if on edge, bounce" block work

rayli1123 wrote:

DinoMaster20 wrote:

The2AndOnly wrote:

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
Maybe
// The custom block should be run without screen refresh
define Move out of edge
repeat until <not <touching [edge v] ?>>
move (-1) steps
end
This will force your sprite out of the edge.
I tried that but then sometimes it still gets stuck inside of the edge and it freezes the program
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?

Powered by DjangoBB