(Looking at the code, I can say with certainty that this doesn't always work, if at all.)
Line 28: Line 28:
 
wait (0.01) secs
 
wait (0.01) secs
 
</scratchblocks>
 
</scratchblocks>
==Workaround==
+
<!-- ==Workaround==
 
{{main|List of Block Workarounds}}
 
{{main|List of Block Workarounds}}
 
The If on Edge, Bounce block can be replicated with the following code, which uses some [[trigonometry]]:
 
The If on Edge, Bounce block can be replicated with the following code, which uses some [[trigonometry]]:
  
<!-- [[File:How to get around the If_on_Edge,_Bounce block.png]] -->
+
<!--[[File:How to get around the If_on_Edge,_Bounce block.png]] --><!--
 
<scratchblocks>
 
<scratchblocks>
 
if <touching [edge v]?> then
 
if <touching [edge v]?> then
Line 43: Line 43:
 
change x by ([sin v] of (direction))
 
change x by ([sin v] of (direction))
 
end
 
end
</scratchblocks>
+
</scratchblocks>  -->
  
 
{{Motion Blocks}}
 
{{Motion Blocks}}
 
[[Category:Motion Blocks]]
 
[[Category:Motion Blocks]]
 
[[de:Pralle vom Rand ab (Block)]]
 
[[de:Pralle vom Rand ab (Block)]]

Revision as of 01:00, 6 June 2014

If on Edge, Bounce
2.0 If On Edge, Bounce.png
Category Motion
Type Stack

The If on Edge, Bounce block is a Motion Block and a Stack Block. The block checks to see if its sprite is touching the edge of the screen with the move steps block — and if it is, the sprite will point in a direction that mirrors the direction from which it is coming. It uses a line perpendicular to the edge to determine the reflection angle.

Example Uses

  • Preventing a sprite from partially leaving the screen (often, this is followed by the Point in Direction block to stop reflection)
  • Reflection
  • Games such as "Pong"
  • Allowing sprites to bounce off the screen:
when gf clicked
forever
if on edge, bounce
move (5) steps
  • It also works for games such as Fish.
forever
turn cw (pick random (-10) to (10)) degrees
move (3) steps
if on edge, bounce
wait (0.01) secs