Discuss Scratch

hi2074
Scratcher
34 posts

going to random specific spots

hi there!

need help with trying to figure out how to make a sprite go to a random spot on the map but without it clipping through the level?

if you can help me big thanks!
ventoaurum
Scratcher
100+ posts

going to random specific spots

im not sure given the context, but i hope this help:

repeat until <not <touching [level v] ?>>
go to x: (pick random (-240) to (240)) y: (pick random (-180) to (180))
end
medians
Scratcher
1000+ posts

going to random specific spots

ventoaurum wrote:

im not sure given the context, but i hope this help:

repeat until <not <touching [level v] ?>>
go to x: (pick random (-240) to (240)) y: (pick random (-180) to (180))
end
Also might be better if you change the -240 to the lowest x, the 240 to the highest x, and do the same for the y.
Woodfur
Scratcher
100+ posts

going to random specific spots

Here's what I'd do. Ventoaurum's solution won't execute at all if it's already in a valid position, but this will always execute at least once.

define go
go to [random position v]
if <touching [level v] ?> then
go
end
hi2074
Scratcher
34 posts

going to random specific spots

big thanks!
ventoaurum
Scratcher
100+ posts

going to random specific spots

Woodfur wrote:

Here's what I'd do. Ventoaurum's solution won't execute at all if it's already in a valid position, but this will always execute at least once.

define go
go to [random position v]
if <touching [level v] ?> then
go
end
bruh i forgot about the go to random position block. thx for adding on to me bro
hi2074
Scratcher
34 posts

going to random specific spots

heres the project for context https://scratch.mit.edu/projects/755275238/
medians
Scratcher
1000+ posts

going to random specific spots

ventoaurum wrote:

Woodfur wrote:

Here's what I'd do. Ventoaurum's solution won't execute at all if it's already in a valid position, but this will always execute at least once.
bruh i forgot about the go to random position block. thx for adding on to me bro
Oh my god same because the 2.0 versions I use have no random position block LOL
Also you could use the solution given above or if you want a random set of positions on the level:

BoltBait made this years ago but I didn't want to link it in case necropost.

Last edited by medians (Feb. 26, 2023 05:07:24)

Powered by DjangoBB