This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-11-24 10:08:05

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Acceleration Code

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?


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#2 2011-11-24 10:32:07

Lar-Rew
Scratcher
Registered: 2010-02-19
Posts: 100+

Re: Acceleration Code

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/uploads/4/6/4/3/4643709/5088060_orig.gif

Oh, and wrong forum bud.  This belongs in All About Scratch.

Last edited by Lar-Rew (2011-11-24 10:32:52)

Offline

 

#3 2011-11-24 12:42:01

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: Acceleration Code

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.


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#4 2011-11-24 12:58:54

Lar-Rew
Scratcher
Registered: 2010-02-19
Posts: 100+

Re: Acceleration Code

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/uploads/4/6/4/3/4643709/5088060_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/uploads/4/6/4/3/4643709/6626973_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.

Last edited by Lar-Rew (2011-11-24 13:01:13)

Offline

 

#5 2011-11-24 13:05:33

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Acceleration Code

What's your current script? Are you still using the key sensing?

Offline

 

#6 2011-11-24 13:26:25

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: Acceleration Code

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.


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#7 2011-11-24 14:02:04

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Acceleration Code

Don't credit me; I didn't help you at all. It was all Lar-Rew.

Offline

 

#8 2011-11-24 22:55:04

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: Acceleration Code

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


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

Board footer