In a script for movement(velocity), I have a section for left movement and right movement. They're set up the same, but for some reason right movement doesn't work.
The part of the script for left and right is:
If key right arrow pressed
set xVel 1
else
set xVel 0
if key left arrow pressed
set xVel -1
else
set xVel 0
change x by xVel
This should work...? Any help would be appreciated.
Edit:
Apparently, whichever I put first in the script is the one that works.
Last edited by Razion (2010-04-06 18:33:40)
Offline
That's a tricky one to spot
. Here is what you are basically saying. (Let's pretend that the right arrow key is pressed). The right arrow key is pressed, so we are going to set velocity to one. BUT WAIT, afterwards there is an if else statment that says if the left arrow key isn't pressed (which it isn't) then set it to 0! So our 1 value just got reset, back to 0. Here is what it should look like:
<when green flag clicked>
<forever>
<if><key[ right arrow ]pressed?>
<set{ velocity }to( 1
<else>
<if><key[ left arrow ]pressed?>
<set{ velocity }to( -1
<else>
<set{ velocity }to( 0
I hope this helped!
Offline
Next time put this kind of topic in the All About Scratch forum.
Offline