Comments (3)
Can you try adding the following after you set the render options:
engine.broadphase.current = 'bruteForce';
This will swap the bruteforce broadphase in rather than the default grid broadphase.
I tested this and it seems to prevent the problem, so it indicates an issue with the grid broadphase.
I'll investigate and try get it fixed, thanks for reporting this!
from matter-js.
I does not look like changing to the bruteForce broadphase works around the problem; I can still reproduce with this method.
By simply adding the line it looks like it fixes the problem, but I think it is changing some of the collision ordering in SAT.collides() which has the result of masking the bug (from what I can tell, of course, a little on this below).
Using the above code, change the rectangle adding order to this:
Matter.World.add(engine.world, Matter.Bodies.rectangle(380.5, 25.5, 102, 102, { isStatic: false, density: 1.0, friction: 0.0, restitution: 1.0 }));
Matter.World.add(engine.world, Matter.Bodies.rectangle(285.5, 323.5, 102, 102, { isStatic: true, density: 1.0, friction: 0.0, restitution: 1.0 }));
Matter.World.add(engine.world, Matter.Bodies.rectangle(193.5, 25.5, 102, 102, { isStatic: false, density: 1.0, friction: 0.0, restitution: 1.0 }));
You'll see this still reproduces the problem when using the bruteForce broadphase.
Side information -- I originally discovered this because on a simpler example it looked like the restitution was wrong with the bruteForce method. Try these two add lines:
Matter.World.add(engine.world, Matter.Bodies.rectangle(321.5, 337.5, 383, 17, { isStatic: true, density: .5, friction: 1, restitution: 0, angle: 0}));
Matter.World.add(engine.world, Matter.Bodies.rectangle(300, 67, 102, 102, { isStatic: false, density: 0.5, friction: 1, restitution: 0.8, angle: 0}));
It doesn't bounce at all. In fact, if you move the box over to the left, it doesn't do a flat bounce:
Matter.World.add(engine.world, Matter.Bodies.rectangle(321.5, 337.5, 383, 17, { isStatic: true, density: .5, friction: 1, restitution: 0, angle: 0}));
Matter.World.add(engine.world, Matter.Bodies.rectangle(200, 67, 102, 102, { isStatic: false, density: 0.5, friction: 1, restitution: 0.8, angle: 0}));
However, changing the ordering makes it bounce as expected:
Matter.World.add(engine.world, Matter.Bodies.rectangle(300, 67, 102, 102, { isStatic: false, density: 0.5, friction: 1, restitution: 0.8, angle: 0}));
Matter.World.add(engine.world, Matter.Bodies.rectangle(321.5, 337.5, 383, 17, { isStatic: true, density: .5, friction: 1, restitution: 0, angle: 0}));
It looks like the difference is that this line is being called in SAT.collides():
if (Vector.dot(collision.normal, Vector.sub(bodyB.position, bodyA.position)) > 0) {
collision.normal = Vector.neg(collision.normal);
}
And this is due to bodyA and bodyB just being swapped when passed into the function. The ordering doesn't seem to matter with the grid broadphase, but let me know if you'd like me to file any individual bugs on these.
from matter-js.
Interesting, thanks for providing these cases, I'll take a look when I can.
from matter-js.
Related Issues (20)
- Render.setSize is not present in the build
- Trying to change seed, to take control of deterministic behavior
- How to suppress body tremors? HOT 2
- Why does the attractor only work on one of the two BODYs? HOT 1
- Using compound bodies with Bodies.fromVertices does not work it just shows a filled in shape. HOT 1
- Why don't bodies sometimes collide? HOT 1
- Constraints with distance limits (e.g. for ropes)
- Why might there be such an error? HOT 1
- Simple Polygon Physics Issues HOT 1
- How to add project to the Wiki gallery ?
- How to scale the world? HOT 2
- [Phaser 3] Position of matter sprite's image not correct in container HOT 1
- loss of sprite quality on mobile HOT 1
- `Composite.translate` didn't move the bodies included
- Create Matter.Bodies.fromVertices with rounded vertices
- MouseConstraint preventing clicks on buttons on mobile. HOT 2
- Vulnerability related to the formula of universal gravitation
- Body with high mass and low inertia behaves erratically
- The startdrag event of dragging a body does not trigger after losing focus.
- How to move camera in matter.js world?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matter-js.