Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matter.Body.applyForce changes based on Runner.delta #1307

Open
luveti opened this issue Jul 19, 2024 · 0 comments
Open

Matter.Body.applyForce changes based on Runner.delta #1307

luveti opened this issue Jul 19, 2024 · 0 comments

Comments

@luveti
Copy link

luveti commented Jul 19, 2024

Given the following example:

<html>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/matter.min.js"></script>
    <body></body>
    <script>
        const engine = Matter.Engine.create()

        const circle = Matter.Bodies.circle(20, 300, 10)

        Matter.Composite.add(engine.world, [
            circle,
            Matter.Bodies.rectangle(400, 5, 800, 10, { isStatic: true }),
            Matter.Bodies.rectangle(400, 600 - 5, 800, 10, { isStatic: true }),
            Matter.Bodies.rectangle(5, 300, 10, 600, { isStatic: true }),
            Matter.Bodies.rectangle(800 - 5, 300, 10, 600, { isStatic: true }),
        ])

        const render = Matter.Render.create({ element: document.body, engine })
        Matter.Render.run(render)

        const runner = Matter.Runner.create({
            delta: 1000 / 60,
            // delta: 1000 / 120,
        })
        Matter.Runner.run(runner, engine)

        Matter.Body.applyForce(circle, circle.position, { x: 0.01, y: 0 })
    </script>
</html>

When delta = 1000 / 60 the circle lands half way across the box.
When delta = 1000 / 120 the circle lands quarter way across the box.

Is this the expected behavior? It seems like every force needs to be doubled, but I would expect the engine to handle this internally. My goal with lowering the delta was to add more stepping of the simulation to prevent objects from phasing through each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant