Discuss Scratch

HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

Ok, so in one of the projects I'm working on, one of the sprites moves based off of a variable changing, not steps or set x and y. It has to work based on the variable changing. Imagine the variable is
p2x
If I have the sprite roatated in a certain direction, how could I have it move in that direction, but without using
movestepsbecauseitwouldn'tupdatethevariable?

Last edited by HoiTemmieColeg (Dec. 11, 2018 03:10:58)

HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

Oops the formatting was messed up. The last line was meant to say
If I have the sprite roatated in a certain direction, how could I have it move in that direction, but without using
movesteps
because it wouldn't update the variable.
deck26
Scratcher
1000+ posts

Movement and Rotation with variables

Don't understand what you mean. Moving using a variable doesn't change the variable.
HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

deck26 wrote:

Don't understand what you mean. Moving using a variable doesn't change the variable.
OK what I'm trying to say is that the project I'm making cannot use move () steps. To move my sprite, I have to change a variable
xy

How could I have him move in the direction he is facing using only
changexby0changeyby0

Of course you would also use math blocks, you just can't use the move () steps block

Last edited by HoiTemmieColeg (Dec. 11, 2018 11:51:59)

PutneyCat
Scratcher
500+ posts

Movement and Rotation with variables

Maybe:

changexbysinofdirection*10changeybycosofdirection*10gotox:xy:y

Last edited by PutneyCat (Dec. 11, 2018 13:03:59)

deck26
Scratcher
1000+ posts

Movement and Rotation with variables

Still unsure why you're avoiding the move n steps block though.
HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

deck26 wrote:

Still unsure why you're avoiding the move n steps block though.
scrollx
deck26
Scratcher
1000+ posts

Movement and Rotation with variables

So if you're scrolling you may prefer to use trigonometry to work out the x and y change. But if you'd rather not for some reason you could actually use a custom block with no screen refresh - store x,y, move n steps, calculate difference for x and y and move back again. All done in a fraction of a second.
HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

PutneyCat wrote:

Maybe:

changexbysinofdirection*10changeybycosofdirection*10gotox:xy:y
Thanks! I'll try it out.
HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

deck26 wrote:

So if you're scrolling you may prefer to use trigonometry to work out the x and y change. But if you'd rather not for some reason you could actually use a custom block with no screen refresh - store x,y, move n steps, calculate difference for x and y and move back again. All done in a fraction of a second.
That might work too. I'll try both and see how it goes.
HoiTemmieColeg
Scratcher
20 posts

Movement and Rotation with variables

PutneyCat wrote:

Maybe:

changexbysinofdirection*10changeybycosofdirection*10gotox:xy:y

deck26 wrote:

So if you're scrolling you may prefer to use trigonometry to work out the x and y change. But if you'd rather not for some reason you could actually use a custom block with no screen refresh - store x,y, move n steps, calculate difference for x and y and move back again. All done in a fraction of a second.

I ended up using the first method. Here is a very early beta of my game:
https://scratch.mit.edu/projects/269780344/

Powered by DjangoBB