Im making a game, but I don't really know how to make it so a sprite accelerates more the longer you hold the move button (W,A,S, or D) down. Could anyone please help me out?
Offline
You'll need a velocity variables. Here is a script that should do what you want. Play around with it to tweak it to your needs.
Oh, and wrong forum bud. This belongs in All About Scratch.
Last edited by Lar-Rew (2011-11-24 10:32:52)
Offline
Lar-Rew wrote:
You'll need a velocity variables. Here is a script that should do what you want. Play around with it to tweak it to your needs.
http://lasergnlsdjkfila.weebly.com/uplo … 0_orig.gif
Oh, and wrong forum bud. This belongs in All About Scratch.
Thanks so much! I changed the code a little so that the yvel actually rotates the sprite. By doing this, I've run into another problem. I want the rotating to slow down over time, but when I did (if yvel>0, change yvel by -1) it just stopped the boat's motion. Can you (or anyone else) help me out? Remember, the yvel now influences rotating, not motion.
Offline
WingsGames wrote:
Lar-Rew wrote:
You'll need a velocity variables. Here is a script that should do what you want. Play around with it to tweak it to your needs.
Oh, and wrong forum bud. This belongs in All About Scratch.Thanks so much! I changed the code a little so that the yvel actually rotates the sprite. By doing this, I've run into another problem. I want the rotating to slow down over time, but when I did (if yvel>0, change yvel by -1) it just stopped the boat's motion. Can you (or anyone else) help me out? Remember, the yvel now influences rotating, not motion.
This should work:
Now let me explain why what you did didn't work.
Think about what happens with your code when they press w. yvel gets changed to 1... and then it gets changed back to 0. With the -0.33 instead of the -1, it gets changed to 1, then to 0.67, and the player turns, then to 0.33, and the player turns, and then to 0.
Last edited by Lar-Rew (2011-11-24 13:01:13)
Offline
What's your current script? Are you still using the key sensing?
Offline
Lar-Rew wrote:
WingsGames wrote:
Lar-Rew wrote:
You'll need a velocity variables. Here is a script that should do what you want. Play around with it to tweak it to your needs.
http://lasergnlsdjkfila.weebly.com/uplo … 0_orig.gif
Oh, and wrong forum bud. This belongs in All About Scratch.Thanks so much! I changed the code a little so that the yvel actually rotates the sprite. By doing this, I've run into another problem. I want the rotating to slow down over time, but when I did (if yvel>0, change yvel by -1) it just stopped the boat's motion. Can you (or anyone else) help me out? Remember, the yvel now influences rotating, not motion.
This should work:
http://lasergnlsdjkfila.weebly.com/uplo … 3_orig.gif
Now let me explain why what you did didn't work.
Think about what happens with your code when they press w. yvel gets changed to 1... and then it gets changed back to 0. With the -0.33 instead of the -1, it gets changed to 1, then to 0.67, and the player turns, then to 0.33, and the player turns, and then to 0.
That worked great! Thanks! I was able to apply it to the forward and backward motion as well, so it fully simulates what I was trying to accomplish! I'll give you and Lar-Rew credit in the project.
Offline
Don't credit me; I didn't help you at all. It was all Lar-Rew.
Offline
Lar-Rew wrote:
WingsGames wrote:
Lar-Rew wrote:
You'll need a velocity variables. Here is a script that should do what you want. Play around with it to tweak it to your needs.
http://lasergnlsdjkfila.weebly.com/uplo … 0_orig.gif
Oh, and wrong forum bud. This belongs in All About Scratch.Thanks so much! I changed the code a little so that the yvel actually rotates the sprite. By doing this, I've run into another problem. I want the rotating to slow down over time, but when I did (if yvel>0, change yvel by -1) it just stopped the boat's motion. Can you (or anyone else) help me out? Remember, the yvel now influences rotating, not motion.
This should work:
http://lasergnlsdjkfila.weebly.com/uplo … 3_orig.gif
Now let me explain why what you did didn't work.
Think about what happens with your code when they press w. yvel gets changed to 1... and then it gets changed back to 0. With the -0.33 instead of the -1, it gets changed to 1, then to 0.67, and the player turns, then to 0.33, and the player turns, and then to 0.
I finished the tutorial of the game! Thanks SO much for helping me make it happen! Check it out at: http://scratch.mit.edu/projects/WingsGames/2173715
Offline