Discuss Scratch

Pitchounette
New Scratcher
6 posts

Random movement and sprite direction

Hi there,
How does one use random movement x and y but have the sprite face the right direction? The direction of the random movement? thanks and have a wonderful day.
wkelly42
Teacher
100+ posts

Random movement and sprite direction

setrotationstyle all around
deck26
Scratcher
1000+ posts

Random movement and sprite direction

Rather than thinking of it as x and y movement think of it as an angle and a distance. Note that rotation style only needs to be set once unless you change it subsequently.

setrotationstyle all aroundsetmydirectiontopickrandom1to360pointindirectionmydirectionmovepickrandom1to30steps
Pitchounette
New Scratcher
6 posts

Random movement and sprite direction

You are so nice and fast! But…I don't see set rotation style in my list of movement…
Pitchounette
New Scratcher
6 posts

Random movement and sprite direction




Oh and I would like them to glide
peppermintpatty5
Scratcher
1000+ posts

Random movement and sprite direction

Pitchounette wrote:

You are so nice and fast! But…I don't see set rotation style in my list of movement…
Are you using Scratch 1.4? If so, you can change the rotation style using the three buttons located slightly under the “file” button.
deck26
Scratcher
1000+ posts

Random movement and sprite direction

Pitchounette wrote:

Oh and I would like them to glide
In that case you want to glide to random x and y values, presumably. x goes from -240 to 240, y from -180 to 180 so you can put those values in two random blocks.
Pitchounette
New Scratcher
6 posts

Random movement and sprite direction

Are you using Scratch 1.4? If so, you can change the rotation style using the three buttons located slightly under the “file” button.

Maybe it is Scratch 1.4…I'm on linux and I installed it that way. I do use the three little buttons (only face left-right) but I don't want them to glide backwards!
deck26
Scratcher
1000+ posts

Random movement and sprite direction

Pitchounette wrote:

Are you using Scratch 1.4? If so, you can change the rotation style using the three buttons located slightly under the “file” button.

Maybe it is Scratch 1.4…I'm on linux and I installed it that way. I do use the three little buttons (only face left-right) but I don't want them to glide backwards!
Ah, the problem I think you're referring to is that unlike ‘move’ the glide block doesn't turn the sprite. So what you probably want to do is get your random x and y coordinates, work out if x is greater than or less than the current value (and turn accordingly) then glide.

setmyxtopickrandom-240to240setmyytopickrandom-180to180ifmyx< xpositionthenpointindirection-90elsepointindirection90glide3secstox:myxy:myy
Pitchounette
New Scratcher
6 posts

Random movement and sprite direction

Thanks. I'll let you know if it works!
radruben
Scratcher
1 post

Random movement and sprite direction

thx
Aqua_Cheetah123
New Scratcher
6 posts

Random movement and sprite direction

Ok, so how would you make it only face 180 degrees or 90 degrees but randomly choose when I place it down
imfh
Scratcher
1000+ posts

Random movement and sprite direction

Aqua_Cheetah123 wrote:

Ok, so how would you make it only face 180 degrees or 90 degrees but randomly choose when I place it down
Welcome to the Scratch forums! To keep things organized, it is usually preferable that you create a new topic to get help in Help With Scripts. This is especially the case when the topic is nearly 4 years old. Next time, please check the date before posting.

You can use this script to randomly choose 90 or 180 degrees:

ifpickrandom1to2=1thenpointindirection90elsepointindirection180
imaboss19
Scratcher
2 posts

Random movement and sprite direction

I want any possible angle!!!!!!
db3t
Scratcher
4 posts

Random movement and sprite direction

deck26 wrote:

Rather than thinking of it as x and y movement think of it as an angle and a distance. Note that rotation style only needs to be set once unless you change it subsequently.

setrotationstyle all aroundsetmydirectiontopickrandom1to360pointindirectionmydirectionmovepickrandom1to30steps

Powered by DjangoBB