Discuss Scratch

Bookz4ever
Scratcher
15 posts

How do you move with the arrow keys?

How do you move with the arrow keys? Please help!
Nolieman1
Scratcher
30 posts

How do you move with the arrow keys?

try this
whenright arrowkeypressedmove10steps
AonymousGuy
Scratcher
1000+ posts

How do you move with the arrow keys?

It depends on the kind of movement you want, but, for movement where basically you can move a sprite up, down, left, and right:
whenclickedforeverifkeyleft arrowpressed?thenchangexby-1Or any negative numberifkeyright arrowpressed?thenchangexby1Or any positive numberifkeydown arrowpressed?thenchangeyby-1Or any negative numberifkeyup arrowpressed?thenchangeyby1Or any positive number
TheLogFather
Scratcher
1000+ posts

How do you move with the arrow keys?

@Nolieman1: I'd recommend against using “when key pressed” hat blocks for movement, usually.
Instead, use the “key pressed” sensor blocks (as in AonymousGuy's example script).

For an explanation of why (one reason, anyway - there are others, too), see this demo project:

http://scratch.mit.edu/projects/18453174

Last edited by TheLogFather (March 17, 2014 22:05:45)

acopper
Scratcher
2 posts

How do you move with the arrow keys?

I have a student who is trying to use the arrow keys to move her sprite (creating a maze). When she pushes the second arrow key (and any consecutive ones after using the first one), her sprite “jumps” to an entirely different place. The only things she has in there are when arrow key is pressed move 10 steps and point in direction degrees. Any ideas what is going on with her project?
TheLogFather
Scratcher
1000+ posts

How do you move with the arrow keys?

acopper wrote:

I have a student who is trying to use the arrow keys to move her sprite (creating a maze). When she pushes the second arrow key (and any consecutive ones after using the first one), her sprite “jumps” to an entirely different place. The only things she has in there are when [up, down, left, right] arrow key is pressed move 10 steps and point in direction [90,-90,180,0] degrees. Any ideas what is going on with her project?
My guess would be that the sprite costume is not centred. Consequently, when its rotation direction changes, it appears to offset by a large amount.

Go into the sprite's costume and click on the button to the top-right of the costume editor pane that has the cross in it (next to the flip buttons). That will show you where the costumes centre is located (and that is the point about which the costume rotates when you change direction). You can then move it to where you actually want it.

Hope that helps!

anna_lillie
Scratcher
13 posts

How do you move with the arrow keys?

whenkeypressedmove1stepspointindirection
acopper
Scratcher
2 posts

How do you move with the arrow keys?

TheLogFather - Thank you so much! I didn't think about having her check that. The costume was far from being centered. Thanks again for the help!!!
Bookz4ever
Scratcher
15 posts

How do you move with the arrow keys?

Thank you all! To move with the arrow keys, follow AnouymusGuy's procedure! Thanks.
derpmeup
Scratcher
1000+ posts

How do you move with the arrow keys?

I'll give you a velocity engine:
First create these variables.
xvelyvel
And then make this script:
whenclickedgotox:0y:0setxvelto0setyvelto0foreverifkeyleft arrowpressed?thenchangexvelby-1ifkeyright arrowpressed?thenchangexvelby1ifkeyup arrowpressed?thenchangeyvelby1ifkeydown arrowpressed?thenchangeyvelby-1setxveltoxvel*0.9changexbyxvelsetyveltoyvel*0.9changeybyyvel
Hope that helped!

Last edited by derpmeup (April 27, 2014 20:54:30)

levtey
Scratcher
100+ posts

How do you move with the arrow keys?

acopper wrote:

I have a student who is trying to use the arrow keys to move her sprite (creating a maze). When she pushes the second arrow key (and any consecutive ones after using the first one), her sprite “jumps” to an entirely different place. The only things she has in there are when arrow key is pressed move 10 steps and point in direction degrees. Any ideas what is going on with her project?
I think it's because the maze wall affects the sprite. Try lowering 10 to 2 or 4.
polemon
Scratcher
3 posts

How do you move with the arrow keys?

whenclicked
foreverifkey leftpressed?thenchangexby-10ifkey rightpressed?thenchangexby10ifkey uppressed?thenchangeyby10ifkey downpressed?thenchangeyby-10

Last edited by polemon (April 28, 2014 11:03:06)

Zacshap21
Scratcher
100+ posts

How do you move with the arrow keys?

acopper wrote:

I have a student who is trying to use the arrow keys to move her sprite (creating a maze). When she pushes the second arrow key (and any consecutive ones after using the first one), her sprite “jumps” to an entirely different place. The only things she has in there are when arrow key is pressed move 10 steps and point in direction degrees. Any ideas what is going on with her project?
Make sure that her cosume isn't really big. There might be a lot of whie in it that she can't see that needs to be erased.
yurt3
Scratcher
10 posts

How do you move with the arrow keys?

whenclicked
set speedto0
foreverifuparowkeypressed?thenchange speedby0.4
then add other arrow keys. Done!

Last edited by yurt3 (May 25, 2014 16:11:26)

dragonlover151
New Scratcher
1 post

How do you move with the arrow keys?

polemon wrote:

whenclicked
foreverifkey leftpressed?thenchangexby-10ifkey rightpressed?thenchangexby10ifkey uppressed?thenchangeyby10ifkey downpressed?thenchangeyby-10
this works great!!!
bestsmartypants
Scratcher
42 posts

How do you move with the arrow keys?

nobody wrote:

polemon wrote:

whenclicked
foreverifkey leftpressed?thenchangexby-10ifkey rightpressed?thenchangexby10ifkey uppressed?thenchangeyby10ifkey downpressed?thenchangeyby-10
this works great!!!
vpmitc
New Scratcher
2 posts

How do you move with the arrow keys?

This way of controlling the sprite works great on Windows, but in UBUNTU if you press two keys at the same time, the sprite keeps moving out of control till it hits the border. It looks like a bug that happens only on UBUNTU or LINUX.

Is there a fix?
lilhawkeye05
Scratcher
15 posts

How do you move with the arrow keys?

Use the when ___ key pressed block 4 times.
Put zero degrees for up, 180 degrees for down, 90 degrees for right and -90 degrees for left.
Snap the move 10 steps block onto each script an then you can add details to make a game! (:

Last edited by lilhawkeye05 (Oct. 4, 2014 21:57:17)

RPFluffy
Scratcher
1000+ posts

How do you move with the arrow keys?

anna_lillie wrote:

whenkeypressedmove1stepspointindirection

uhhh, no!

Do this instead:

whenclickedforeverifkeyUp Arrowpressed?thenchangeyby1Must Always be positiveifkeyDown Arrowpressed?thenchangeyby-1Must Always be negativeifkeyLeft Arrowpressed?thenchangexby-1Must Always be negativeifkeyRight Arrowpressed?thenchangexby1Must Always be positive

Don't do this as one key will dominate others:

whenclickedforeverifkeyUp Arrowpressed?thenchangeyby1elseifkeyDown Arrowpressed?thenchangeyby-1elseifkeyRight Arrowpressed?thenchangexby1elseifkeyLeft Arrowpressed?thenchangexby-1

Last edited by RPFluffy (Oct. 5, 2014 00:14:54)

TRIZO12
Scratcher
33 posts

How do you move with the arrow keys?

http://scratch.mit.edu/projects/28662862
This is a Project with a simple moving engine.
You're welcome to Remix!

Powered by DjangoBB