Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how do i make a sprite look at a random direction?
- Not_Nik0
-
Scratcher
44 posts
how do i make a sprite look at a random direction?
im making a bomb attack for my game that shoots projectiles in a random direction but i dont know how to do this. Can some one please help?
- RealKreeky
-
Scratcher
78 posts
how do i make a sprite look at a random direction?
point in direction (pick random (-180) to (180))That should do it
- medians
-
Scratcher
1000+ posts
how do i make a sprite look at a random direction?
This?

Edit: Or above.

Edit: Or above.
Last edited by medians (Jan. 8, 2023 02:30:11)
- RealKreeky
-
Scratcher
78 posts
how do i make a sprite look at a random direction?
This?or use this one; which ever one you prefer
Edit: Or above.
Edit: they both do work
Last edited by RealKreeky (Jan. 8, 2023 02:37:23)
- Not_Nik0
-
Scratcher
44 posts
how do i make a sprite look at a random direction?
alright thx 

Last edited by Not_Nik0 (Jan. 8, 2023 02:49:37)
- PurpleSuit
-
Scratcher
500+ posts
how do i make a sprite look at a random direction?
if you only want it to look left or right you could also do this
when green flag clicked
forever
if <something happens> then
set [decider] to (pick random (1) to (2))
if <[decider] = [1]> then
point in direction 90
else
point in direction -90
end
end
end
- medians
-
Scratcher
1000+ posts
how do i make a sprite look at a random direction?
if you only want it to look left or right you could also do thisCan't you just use rotation style?? And this seems to be solved.
- awesome-llama
-
Scratcher
1000+ posts
how do i make a sprite look at a random direction?
point in direction (pick random (-180) to (180))That should do it
This?Minor issue with both of these, there is a direction that is slightly more likely to be chosen. RealKreeky's one could pick -180 or 180 which are both the same direction, medians' could pick 0 or 360 which is both the same.
Edit: Or above.
So the fix for this is to make sure there are only 360 different directions that can be chosen, not 361.
e.g.
point in direction (pick random (0) to (359))or
point in direction (pick random (-179) to (180))
Though if you want to pick random floating point numbers this will not be a problem, the way those numbers are chosen make this work:
point in direction (pick random (0.0) to (360.0))
- PurpleSuit
-
Scratcher
500+ posts
how do i make a sprite look at a random direction?
maybe you want it to point in another direction not that afterwards.if you only want it to look left or right you could also do thisCan't you just use rotation style?? And this seems to be solved.
- Discussion Forums
- » Help with Scripts
-
» how do i make a sprite look at a random direction?