Giter VIP home page Giter VIP logo

Comments (3)

liabru avatar liabru commented on May 2, 2024

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.

jmfd avatar jmfd commented on May 2, 2024

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.

liabru avatar liabru commented on May 2, 2024

Interesting, thanks for providing these cases, I'll take a look when I can.

from matter-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.