Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhysicsJS Friction Behavior

I am new to physicsjs and am creating some test simulations in order to become familiar with the library.

I want to simulate multiple boxes sliding across the screen which all experience different degrees of friction. So far I have 3 boxes which start on the left border of the screen and all have a pos xvel. I am unsure what the best approach is to add friction to the simulation. all 3 boxes should not be affected the same way by friction. Therefor i need some way of applying a general friction algorithm to all the boxs, however the amount of friction needs to depend on what box it is currently acting on.

like image 781
lufthansa747 Avatar asked Apr 23 '26 18:04

lufthansa747


1 Answers

Friction is built in (but it's not the greatest algorithm).

Just use:

Physics.body('rectangle', {
     width: 40,
     height: 40,
     cof: 0.5, // <-- change the friction. range [0, 1]
     x: ...
     ...
});
like image 92
Jasper Avatar answered Apr 26 '26 09:04

Jasper