Discuss Scratch

TheElementGuy_Test
Scratcher
16 posts

Keep Sprite From Going Off Screen Random Block

Hello, I am using
go to (random position v)
to make a sprite go somewhere random. I know the width and height, so how can I keep it onstage?
Eagle138
Scratcher
500+ posts

Keep Sprite From Going Off Screen Random Block

You could make 2 variables called pos_x and pos_y. Then, do this:

set [pos_x v] to (pick random [min screen height] to [max screen height])
set [pos_y v] to (pick random [min screen height] to [max screen height])
go to x: (pos_x) y: (pos_y)

Hope this helps!

Last edited by Eagle138 (Feb. 26, 2022 04:11:19)


~ Eagle38
coder/artist/noob animator :: he/they :: unconventional :: comment ‘e’ on my profile if you see this
just call me Eagle
fancy signature banner coming…one day
TheElementGuy_Test
Scratcher
16 posts

Keep Sprite From Going Off Screen Random Block

Thank you!
flofoom
Scratcher
4 posts

Keep Sprite From Going Off Screen Random Block

This is how you do it
when green flag clicked
if <touching [ edge] ?> then
repeat until <not <touching [ edge] ?>>
if on edge, bounce
end
point in direction ( 90)
end

Powered by DjangoBB