# Bouncing ball bounces too much

**URL:** <https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766>\
**Category:** Help\
**Created:** [June 16, 2021, 6:36pm UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766 "2021-06-16T18:36:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![salieri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salieri/32/7275_2.png) [@salieri](https://forum.makecode.com/u/salieri)\
**Post date:** [June 16, 2021, 6:36pm UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/1 "2021-06-16T18:36:43Z")

</div>

![bounce](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/ce5e601a468b2587023b7ec01e77972b9d14dc11.png)

Hey guys, I’m trying to make a pinball game. I want the ball to bounce off of walls but also eventually come to a stop. I have se the sprite to bounce on the wall. I have also given it an Y acceleration.

The ball starts at Y 0 with zero velocity

Expected behavior: ball accelerates to a wall, bounces and then doesn’t quite make it back to Y 0 because of the ay. Each bounce isn’t as high as the last. (you know, like a ball 🙂

What happens: the ball actually goes beyond Y 0 cause each bounce to go higher than the last until it reaches the opposite wall. The ball accelerates infinitely.

I’m not sure if I did something wrong or I can add something simple to make it work right! Thanks! Still new with all this.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [June 16, 2021, 9:06pm UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/2 "2021-06-16T21:06:38Z")

</div>

Can you post your code? (as a link) It seems right in the screenshot you gave us but maybe something fishy is going on with the rest?

---

<div class="post-metadata">

**Author:** ![salieri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salieri/32/7275_2.png) [@salieri](https://forum.makecode.com/u/salieri)\
**Post date:** [June 16, 2021, 10:36pm UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/3 "2021-06-16T22:36:34Z")

</div>

Here is the link. [https://makecode.com/\_XuVDRvUFFhc3](https://makecode.com/_XuVDRvUFFhc3)  
You can see the ball keep bouncing higher and higher if you leave it alone.

---

<div class="post-metadata">

**Author:** ![salieri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salieri/32/7275_2.png) [@salieri](https://forum.makecode.com/u/salieri)\
**Post date:** [June 19, 2021, 1:05am UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/4 "2021-06-19T01:05:12Z")

</div>

I tested this on the side of the screen as well as my tilemap walls. Same thing happens, the ball bounces higher than it fell.

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [June 19, 2021, 1:10am UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/5 "2021-06-19T01:10:34Z")

</div>

This one’s a known bug – the root cause of the issue is that we calculate the change in velocity due to acceleration once per sprite at the beginning of the frame, but the bounce is happening part way through the frame, resulting in a slightly higher velocity than you would expect.

I’m hoping to get a chance to fix this in some way for the next release – getting it exactly right might not be feasible without impacting performance, but we should be able to get it closer to correct and we can probably also support friction along with acceleration (as right now only one of the two will work at the same time) to make the interaction more realistic.

---

<div class="post-metadata">

**Author:** ![salieri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salieri/32/7275_2.png) [@salieri](https://forum.makecode.com/u/salieri)\
**Post date:** [June 19, 2021, 3:00am UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/6 "2021-06-19T03:00:23Z")

</div>

Ah I was just messing with friction trying to get it to work when I read your reply.

Thank you so much. Sounds like friction working with acceleration is what I need. I can’t wait to see it updated! Thank you for the info.

---

<div class="post-metadata">

**Author:** ![salieri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salieri/32/7275_2.png) [@salieri](https://forum.makecode.com/u/salieri)\
**Post date:** [July 30, 2021, 11:54pm UTC](https://forum.makecode.com/t/bouncing-ball-bounces-too-much/8766/7 "2021-07-30T23:54:06Z")

</div>

Check out my little work around 😃

 ![Screenshot 2021-07-30 172716](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2326ec93b7d09b1e5188729935a3f6e1b9de3305.png)
