almost every comment on my fish hunt and fish chomp games has told me that i have a problem. if an arrow key is pressed your fish gains speed going in the direction of the arrow. this will make your fish go off screen if you keep going in that direction. i want to make a way that when the key isnt pressed that the fish will come to a stop but all my scripts havent worked. this is what i have so far
<when green flag clicked>
<forever>
<if><key[ up arrow pressed ]pressed?>
<change{ y velocity }by( 0.2
this makes my fish go up and increase in speed if that key is pressed.
i have tried this to make my fish come to a stop
<when green flag clicked>
<forever>
<if><key[ up arrow pressed ]pressed?>
<change{ y velocity }by( 0.2
<end>
<if><< <not> >><key[ up arrow pressed ]pressed?>
<repeat until><( <{ y velocity }> <=> 0 )>
<change{ y velocity }by( -0.5
<end>
but for some reason this doesnt solve my problem
i have also tried:
<when green flag clicked>
<forever>
<if><key[ up arrow pressed ]pressed?>
<change{ y velocity }by( 0.2
<if><< <not> >><key[ up arrow pressed ]pressed?>
<repeat until><( <{ y velocity }> <=> 0 )>
<change{ y velocity }by( -0.5
<end>
but this hasnt worked either. please help!
Last edited by viper650 (2008-06-01 21:48:18)
Offline
For the bottom of the second one, instead of (.5), use (-.5)
Offline
You are changing the Y velocity by a positive value...(.5) which is going to make it bigger! You want to try changing it by a negative value (-.5 maybe) which will make it smaller.
Also, your loop is going to have trouble...since you are asking it to continue until it exactly equals zero, which it might have trouble with, due to round off error. A safer test would be
[blocks]
<repeat until><( <{ y velocity }> <<> 0 )>
<change{ y velocity }by( -.5
<end>
[/blocks]
A technique I often use, to decrease the velocity gradually, is to multiply it by a fraction, if the arrow key is not being pressed, something like
[blocks]
<set{ y velocity }to( (( <{ y velocity }> <*> 0.95 ))
[/blocks]
Last edited by Paddle2See (2008-06-01 21:55:21)
Offline
Hey, I just made a fighter pilot game (click my name, it's the newest one, otherwise it's called fighter pilot) and it uses velocity to speed up/slow down (though it's multi-player, look at one even though there the same). You can use those scripts!
Offline
viper650 wrote:
i have tried a multitude of varieties of what you said i should do yet it still hasn't slowed down the velocity gradually....
Please check out this version. I will delete it once you are done with it.
http://scratch.mit.edu/projects/Paddle2SeeFixIt/178613
Offline