Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Making the ball go faster in pong
- Gnodab
-
2 posts
Making the ball go faster in pong
Hi I just started working with Scratch and Im having tons of fun finding the solution to the problems at hand, but I can't seem to find a way to make the speed of the ball exponentially increase when it hits the paddle.
U can check on my profile what I have so far. Thanks in advance!
U can check on my profile what I have so far. Thanks in advance!
- Lifeoftheparty29
-
17 posts
Making the ball go faster in pong
Change the number of steps the ball moves to a variable. Have that variable increase when the ball hits the paddle.
- Ayarkay
-
73 posts
Making the ball go faster in pong
Like Lifeoftheparty29 said, you'd want the number of steps that the ball moves by to be a variable, let's call it Speed. Once you want the the ball to move faster, you multiply the Speed variable by a constant number. For example, whenever you want the speed to increase, you'd run:
If you wanted a linear increase in speed instead of an exponential one, you'd simply do:
Then, all you need is a way to periodically launch the above code. You could have a counter variable that increases by 1 every time a paddle is hit. Then, every time the counter reaches a certain number, it increases the speed, and then resets the counter.
Increasing the 1.5 value will cause the speed to increase faster, while a lower value closer to 1 will cause the speed to increase more slowly. Values lower than 1 will cause the speed to exponentially decrease.
If you wanted a linear increase in speed instead of an exponential one, you'd simply do:
The value that you add on to Speed would determine how much faster the ball would go every time you increased its speed.
Then, all you need is a way to periodically launch the above code. You could have a counter variable that increases by 1 every time a paddle is hit. Then, every time the counter reaches a certain number, it increases the speed, and then resets the counter.
Last edited by Ayarkay (July 21, 2017 20:39:20)
- Gnodab
-
2 posts
Making the ball go faster in pong
I did something similar with variables and functions, but obviously not correct. Anyways good to know that I was looking in the right direction at least. Thanks!
- deck26
-
1000+ posts
Making the ball go faster in pong
Please don't spam or necropost. nbkuftc
- The_Imaginarium
-
1000+ posts
Making the ball go faster in pong
Please don't spam or necropost.
- samq64
-
1000+ posts
Making the ball go faster in pong
(Didn't relise the OP was 4 years old and the topic was necroposted.)
Last edited by samq64 (April 27, 2021 13:06:26)
- Discussion Forums
- » Help with Scripts
-
» Making the ball go faster in pong