# How to make ball bouncy in matterjs

**URL:** <https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250>\
**Category:** Libraries\
**Created:** [April 14, 2019, 4:37am UTC](https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250 "2019-04-14T04:37:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blkpanther](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@blkpanther](https://discourse.processing.org/u/blkpanther)\
**Post date:** [April 14, 2019, 4:37am UTC](https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250/1 "2019-04-14T04:37:08Z")

</div>

Hi I adapted this snippet of code from [here](https://github.com/shiffman/p5-matter/blob/master/01_basics/sketch.js) However, despite the restitution, the objects aren’t bouncy at all. Is there anything I need to change?

```auto
// This example is based on examples from: http://brm.io/matter-js/

var Engine = Matter.Engine;
var Render = Matter.Render;
var World = Matter.World;
var Bodies = Matter.Bodies;
var Composite = Matter.Composite;

var engine;

var boxA;
var boxB;
var ground;

function setup() {
  createCanvas(800, 600);

  // create an engine
  engine = Engine.create();

 let options = {
    isStatic: true,
    restitution: 0.8
  }
  // create two boxes and a ground
  boxA = Bodies.rectangle(400, 200, 80, 80);
  //boxB = Bodies.circle(490, 50, 80, 80);
  boxB = Bodies.circle(490, 50, 20, 20);
  ground = Bodies.rectangle(400, 610, 810, 60, options);

  World.add(engine.world, [boxA, boxB, ground]);

  // run the engine
  Engine.run(engine);
}

// Using p5 to render
function draw() {

  // var bodies = Composite.allBodies(engine.world);

  background(51);

  var vertices = boxA.vertices;
  fill(255);
  beginShape();
  for (var i = 0; i < vertices.length; i++) {
    vertex(vertices[i].x, vertices[i].y);
  }
  endShape();

  // boxB vertices
  var vertices = boxB.vertices;
  fill(255);
  beginShape();
  for (var i = 0; i < vertices.length; i++) {
    vertex(vertices[i].x, vertices[i].y);
  }
  endShape();

  // Ground vertices
  var vertices = ground.vertices;
  beginShape();
  fill(127);
  for (var i = 0; i < vertices.length; i++) {
    vertex(vertices[i].x, vertices[i].y);
  }
  endShape();
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 14, 2019, 4:51am UTC](https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250/2 "2019-04-14T04:51:48Z")

</div>

if you go  
[https://github.com/shiffman/p5-matter](https://github.com/shiffman/p5-matter) and

- download the ZIP
- unzip it to any directory
- go down to  
…\p5-matter-master\01\_basics\
- double click index.html

i think you get what it is supposed to do??  
( test under win7 / 64bit // firefox browser )

so can you tell us what/HOW you try to do it,  
there is much more info about your working environment needed!

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [April 14, 2019, 8:01am UTC](https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250/3 "2019-04-14T08:01:24Z")

</div>

shouldn’t options be applied to the active bodies as well? [this](https://editor.p5js.org/hotfooted/sketches/k8dCcSrIX) works with restitution set on both actives

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 14, 2019, 1:02pm UTC](https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250/4 "2019-04-14T13:02:10Z")

</div>

Some very old posts about “matter.js” library: 🔗

- [Forum.Processing.org/two/discussions/tagged/matter.js](http://Forum.Processing.org/two/discussions/tagged/matter.js)

---

<div class="post-metadata">

**Author:** ![blkpanther](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@blkpanther](https://discourse.processing.org/u/blkpanther)\
**Post date:** [April 14, 2019, 6:42pm UTC](https://discourse.processing.org/t/how-to-make-ball-bouncy-in-matterjs/10250/5 "2019-04-14T18:42:43Z")

</div>

Thank you! It’s really helpful.
