# A way to make a sprite bounce?

**URL:** https://forum.code.org/t/a-way-to-make-a-sprite-bounce/25808
**Category:** CS Discoveries
**Tags:** csd-unit-3-lesson-9
**Created:** [March 22, 2019, 5:19pm UTC](https://forum.code.org/t/a-way-to-make-a-sprite-bounce/25808 "2019-03-22T17:19:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ben\_kuehl](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@ben\_kuehl](https://forum.code.org/u/ben_kuehl)
#### Post date: [March 22, 2019, 5:19pm UTC](https://forum.code.org/t/a-way-to-make-a-sprite-bounce/25808/1 "2019-03-22T17:19:17Z")

</div>

Anybody have any idea if there is a way you could make a sprite look like it was bouncing. A student was creating a scene with a bunny and she wanted it to bounce. We tried to play around with x and y but nothing could quite get us there. I am assuming maybe once they have booleans and stuff it may be possible?

---

<div class="post-metadata">

### Author: ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)
#### Post date: [March 24, 2019, 1:59pm UTC](https://forum.code.org/t/a-way-to-make-a-sprite-bounce/25808/2 "2019-03-24T13:59:00Z")

</div>

Ben,

Just a clarifying question - you would want the first “bounce” to be higher/highest and then each “bounce” afterwards be lower until the bunny rest on the ground? Off the top of my head you could have a variable (“bounce”) that would be equal to the y value and would decrease according to how many time the bunny has touched the ground sprite. You’ll get into this a little bit in Chapter 2 of Unit 3, but the decreasing height on each bounce isn’t taught.

Let me know if you have further questions / if it works!

Brad

---

<div class="post-metadata">

### Author: ![kookooloopdaking](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/kookooloopdaking/32/5224_2.png) [@kookooloopdaking](https://forum.code.org/u/kookooloopdaking)
#### Post date: [November 15, 2019, 8:42pm UTC](https://forum.code.org/t/a-way-to-make-a-sprite-bounce/25808/3 "2019-11-15T20:42:13Z")

</div>

If you have a ground sprite you could do:

var sprite = createSprite(200,200);  
sprite.setAnimation(“bunny\_sprite”);  
var ground = createSprite(200,375,400,50);

function draw() {

if (sprite.isTouching(ground)) {

ground.displace(sprite);  
sprite.velocityY = -10;

} else {

sprite.velocityY -= 0.5;

}

}
