# Jumping mechanic

**URL:** <https://discourse.processing.org/t/jumping-mechanic/34499>\
**Category:** Coding Questions\
**Created:** [January 7, 2022, 10:06am UTC](https://discourse.processing.org/t/jumping-mechanic/34499 "2022-01-07T10:06:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![parichko](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@parichko](https://discourse.processing.org/u/parichko)\
**Post date:** [January 7, 2022, 10:06am UTC](https://discourse.processing.org/t/jumping-mechanic/34499/1 "2022-01-07T10:06:06Z")

</div>

What is the best way to add a jumping mechanic to a shape in p5js

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [January 7, 2022, 10:27am UTC](https://discourse.processing.org/t/jumping-mechanic/34499/2 "2022-01-07T10:27:07Z")

</div>

When a key is pressed, and that key is the space bar, set the object’s velocity to some negative value. You might also want to check your shape is standing on solid ground.

Each time you simulate the object’s motion, add it’s acceleration (probably a positive constant) to its velocity, and its velocity to its position.

Then just make sure you’re drawing the shape at its position.
