# Stop ball less abruptly

**URL:** <https://discourse.processing.org/t/stop-ball-less-abruptly/32572>\
**Category:** Coding Questions\
**Created:** [October 3, 2021, 8:44am UTC](https://discourse.processing.org/t/stop-ball-less-abruptly/32572 "2021-10-03T08:44:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [October 3, 2021, 8:44am UTC](https://discourse.processing.org/t/stop-ball-less-abruptly/32572/1 "2021-10-03T08:44:02Z")

</div>

if you press space the ellipse jumps, but it stops very abruptly how can i slow it down instead?

```auto
//visual
PImage shrek;
boolean invert= false;
//timer

//moving
float charx=0;
float chary=563-25;
boolean jumping= false;
float gravity= 10;
float jumpingheight=200;

void setup() {
  size(1000, 563);
  shrek= loadImage("shrek.jpg");
}

void draw() {
  frameRate(60);
  //visual
  background(shrek);
  color(255);
  ellipse(charx, chary, 50, 50);

  //timer
  println(millis()/1000);
  if (millis()/1000%300==0&&millis()/1000>10&& invert==false) {
    invert=true;
  }
  if (millis()/1000%600==0&&millis()/1000>10&& invert==true) {
    invert=false;
  }
  if (invert==true) {
    filter(INVERT);
  }

  //moving

  if (keyPressed) {
    //move left with a
    if (key == 'a'&&invert==false) {
      charx=charx-10;
    } 

    //move right with d
    if (key == 'd'&&invert==false) {
      charx=charx+10;
    }

    //move right with a
    if (key == 'a'&&invert==true) {
      charx=charx+10;
    } 

    //move left with d
    if (key == 'd'&&invert==true) {
      charx=charx-10;
    }

    if (key == ' '&&chary>height-jumpingheight) {
      jumping=true;
    }
  }
  if (charx>=width-25) {
    charx=width-25;
  }

  if (charx<=0+25) {
    charx= 0+25;
  }
  if (jumping==true) {
    chary=chary-10;
    charx=charx+0.1;
    if (chary<=height-jumpingheight) {
      jumping=false;
    }
  }
  if (chary!=height-25&&jumping==false) {
    chary+=gravity;
  }

}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 3, 2021, 10:12am UTC](https://discourse.processing.org/t/stop-ball-less-abruptly/32572/2 "2021-10-03T10:12:05Z")

</div>

Hello,

> [@MoonAlien822](#):
>
> how can i slow it down instead?

Easing.

`:)`

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [October 3, 2021, 11:06am UTC](https://discourse.processing.org/t/stop-ball-less-abruptly/32572/3 "2021-10-03T11:06:22Z")

</div>

this is what i ended up with maybe not exactly easing but im good with this, one more question. how do i make it so the ball can’t jump again until you hit the ground, or at least a way that you cant jump in mid air

```auto
//visual
PImage shrek;
boolean invert= false;
//timer

//moving
float charx=0;
float chary=563-25;
boolean jumping= false;
float gravity= 10;
float jumpingheight=100;
float jumpspeed;

void setup() {
  size(1000, 563);
  shrek= loadImage("shrek.jpg");
}

void draw() {
  frameRate(60);
  //visual
  background(shrek);
  color(255);
  ellipse(charx, chary, 50, 50);

  //timer
  println(millis()/1000);
  if (millis()/1000%300==0&&millis()/1000>10&& invert==false) {
    invert=true;
  }
  if (millis()/1000%600==0&&millis()/1000>10&& invert==true) {
    invert=false;
  }
  if (invert==true) {
    filter(INVERT);
  }

  //moving
    if (charx>=width-25) {
    charx=width-25;
  }
  jumpspeed= int(dist(0, jumpingheight, 0, chary)/20);
  
  if (chary>height-25) {
    chary=height-25;
  }
  if (keyPressed) {

    //move left with a
    if (key == 'a'&&invert==false) {
      charx=charx-10;
    } 

    //move right with d
    if (key == 'd'&&invert==false) {
      charx=charx+10;
    }

    //move right with a
    if (key == 'a'&&invert==true) {
      charx=charx+10;
    } 

    //move left with d
    if (key == 'd'&&invert==true) {
      charx=charx-10;
    }
    //jump with space
    if (key == ' '&&chary>height-jumpingheight) {
      jumping=true;
    }
  }

  if (charx<=0+25) {
    charx= 0+25;
  }
  if (jumping==true) {
    chary=int(chary-jumpspeed);
    charx=charx+0.1;
    if (jumpspeed<10&&chary<height-30) {
      jumping=false;
    }
  }
  if (chary!=height-25&&jumping==false) {
    chary+=gravity;
  }
}

```
