Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matter.js: Adding a Bounce Property on Objects

I am looking at using Matter.js, a javascript physics engine, to have a bouncy ball in a simple game. It appears on their API that Matter might not have a property to change the bounciness of an object. Does anyone have any idea how I might go about implementing this?

like image 839
matterickson Avatar asked Mar 18 '15 22:03

matterickson


1 Answers

Maybe you're looking for restitution?

https://brm.io/matter-js/docs/classes/Body.html#property_restitution

A Number that defines the restitution (elasticity) of the body. The value is always positive and is in the range (0, 1). A value of 0 means collisions may be perfectly inelastic and no bouncing may occur. A value of 0.8 means the body may bounce back with approximately 80% of its kinetic energy. Note that collision response is based on pairs of bodies, and that restitution values are combined with the following formula:

like image 128
bvaughn Avatar answered Nov 05 '22 20:11

bvaughn