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

I'm setting the same force with applyForce but the path rarely it's equal. #1167

Closed
dFrance opened this issue Oct 21, 2022 · 8 comments
Closed
Labels

Comments

@dFrance
Copy link

dFrance commented Oct 21, 2022

Hi everyone, i'm trying to launch a ball to top, in a plinko game, but i could't launch the ball to the same height even setting the same force with applyForce. Sometimes the ball up 600px, other 800px and rarely do the same path when drop by the plinko.

When i create the ball at the top of the plinko the ball ALWAYS do the same path, always. So i'd like to reproduce this behavior but launching the ball. Anyone has an idea how can i do this?

If you've some doubt let me know to clarify.

@liabru
Copy link
Owner

liabru commented Oct 24, 2022

Can you try setting runner.isFixed to true and let me know if that solves?

@dFrance
Copy link
Author

dFrance commented Oct 25, 2022

Hi @liabru, i tried but i didn't success. So i noticed that when i launch the ball with a timeout, e.g 500ms, the ball always do the same path. So i imagine that what you suggested make sense but i couldn't implement. Follow some parts of my code.

Here i create the engine and render.

const engine = Engine.create();
const renderer = Render.create({
        element: sectionTag,
        engine: engine,
        options: {
          width: canvaW,
          height: canvaH,
          background: backgroundImageCanvas
            ? backgroundImageCanvas
            : backgroundColorCanvas,
          backgroundSize: "100%",
          backgroundPosition: "-8px 1px",
          backgroundRepeat: "no-repeat",
          showDebug: false,
          wireframes: false,
          pixelRatio: window.devicePixelRatio,
        },
      });

and at the final i run

var runner = Runner.create({
        isFixed: true,
      });

      Render.run(renderer);
      Runner.run(runner, engine);

Am i doing something wrong? I'll try read again the doc.
Anyway thanks for the tip.

@mateusgamba
Copy link

I'm facing the same issue :(

@liabru
Copy link
Owner

liabru commented Nov 8, 2022

Do you have a link to an example I could try? Are you launching the ball exactly the same every time?

@dFrance
Copy link
Author

dFrance commented Nov 28, 2022

Hi @liabru, sorry for delay. I had a lot tasks last weeks. Follow my link to you see. I'm launching the ball with the same force, from the same position and setup the runner with isFixed: true, but many times i got different simulations. Do you know what i could do wrong. I need to get the same simulation independent the time that i launch.
https://codepen.io/difrance/pen/rNKrxzz

@liabru
Copy link
Owner

liabru commented Nov 28, 2022

This is due to changing timeScale which is actually changing the timestep so it's no longer fixed. Removing that from your code seems to give the same results:

	function launchPinball() {
    // var timescale = ((1000 / runner.fps) / 16).toFixed(2);
    // engine.timing.timeScale = timescale;
		updateScore(0);
		Matter.Body.setPosition(pinball, { x: 465, y: 765 });
		Matter.Body.setVelocity(pinball, { x: 0, y: -35 });
		Matter.Body.setAngularVelocity(pinball, 0);
	}

I've made a note to improve the docs around this.

@dFrance
Copy link
Author

dFrance commented Nov 28, 2022

@liabru when i removed this part of code and i faced two issues. The first is that i don't have the same simulation e.g in 10 times. The second is when you use different frame rate you have different simulation between each frame rate. So in 60hz you will have simulations similar and close, still not equal. However if you change to another monitor, 120hz, you'll have another power, gravity another simulation, for my game it is vital. I updated the code to you test.

@liabru
Copy link
Owner

liabru commented Jun 24, 2024

As of 0.20.0 there is now built in Matter.Runner support by default for fixed timestep with high refresh displays see #1300.

Therefore hopefully this will now be much easier. Thanks for the report!

@liabru liabru closed this as completed Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants