(Redirected from If on Edge, Bounce)

If on Edge, Bounce
if on edge, bounce
Category Motion
Type Stack
Introduced in 10Jul04 (0.x)

The if on edge, bounce block is a Motion Block and a stack block. The block checks to see if a sprite is touching the edge of the screen, and if it is, the sprite will point in a direction that mirrors the direction from which it was coming. It uses the edge as a mirror to determine the reflection angle. The block will also push the sprite out of the edge of the screen.

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 the user wants a specific sprite to be in the screen without touching the edge.
when gf clicked
forever
move (10) steps
if on edge, bounce
  • It also works for games such as fish.
when gf clicked
forever
turn cw (pick random (-10) to (10)) degrees
move (3) steps
if on edge, bounce
wait (0.01) seconds

Workaround

Main article: List of Block Workarounds

This block can be replicated by detecting if the sprite is beyond the edge of the screen, and changing the sprite's direction if this is the case:

if <[240] < ([abs v] of (x position))> then 
    point in direction ((0)-(direction))
end
if <[180] < ([abs v] of (y position))> then
    point in direction ((180)-(direction))
end

However, the workaround is not perfect, as it does not push the sprite out of the edge of the screen. Additionally, because the sprite's direction changes based on its coordinates rather than its actual shape, sprites with costumes not centered about the costume center may appear bounce late or early.

Bounce Block

Some users in the suggestions forum have requested a generalized bounce::motion block, which would allow sprites to bounce when they collide with other sprites or with colors.[1][2][3] The block, however, has been rejected, because of how ambiguous the implementation of such a block is.[4][5]

See Also

References

Cookies help us deliver our services. By using our services, you agree to our use of cookies.