question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simulation speed too fast

See original GitHub issue

Tried to look but could not see anyone else talking about this issue.

So I have noticed that at least in Chrome 77/78 and Firefox 70 Mater js simulation runs roughly double the speed than in older browsers. If I run same code in Chrome 74 (happened to be the version OBS Browser uses atm) it runs like normal.

So I don’t know what, but something has changed in newer browsers that make Mater js run faster.

But I have come up with an temporary fix, at least for Chrome. In setup I put

function setup(){
	engine = Engine.create();
	// Checks version and adjust timeScale
	if (navigator.version > 74) {
		engine.timing.timeScale = 0.55;
	}
	Engine.run(engine);
}

and use these functions to get browser version

// Returns browser name and version, found it from here https://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser
navigator.sayswho = (function(){
    var ua= navigator.userAgent, tem, 
    M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
    if(/trident/i.test(M[1])){
        tem=  /\brv[ :]+(\d+)/g.exec(ua) || [];
        return 'IE '+(tem[1] || '');
    }
    if(M[1]=== 'Chrome'){
        tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
        if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
    }
    M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
    if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
    return M.join(' ');
})();

// Returns just version as a number
navigator.version = (function(){
	var v = navigator.sayswho.split(" ")[1];
	return parseInt(v);
})();

Would not take much adjustment to make temporary fix for other browsers but I mainly need/use chrome.

Biggest problem I see with this issue is that when people update to newer versions of browsers (at least Chrome 77 and newer) is that games on the web that use Mater js is going to run too fast.

EDIT: Forgot to mention that I don’t use the render part of Matter js in case that could affect the speed? I have built my own system to “attach” html elements to Matter js object body. Just reads the body position and move the element with js/css.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
wassfilacommented, Jan 19, 2020

@ZpeedTube , I think this can easily be fixed, feel free to have a look at the solution I linked to this tikcet. As long as you call the run inside

    requestAnimationFrame( animate );

this function should be in sync with the refresh rate, and the solution I suggested adjust the time parameters by itself so no hardware specific configuration is needed. I hope this could help with your issue.

2reactions
wassfilacommented, Jan 31, 2020

@ZpeedTube Welcome. Glad this idea from #818 helped 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simulation Speed Too Fast - Autodesk Community - Fusion 360
How do I slow down the simulation speed? I need to see the machining processes a little slower and don't want to have...
Read more >
Simulation speed is too fast : r/PlanetZoo - Reddit
However I have one main issue with the game, and that is the simulation speed is too fast. I often have to pause...
Read more >
Game speed is too fast :: Cities: Skylines General Discussions
The game slows down considerably when your city gets big. This is because your computer needs to do a lot of calculations for...
Read more >
Flight Simulator speeding up time explained - Eurogamer
It's possible to speed up time if you want to get through part of a flight faster with the sim rate feature -...
Read more >
Simulation run too fast - ArduPilot Discourse
Hi All, I have set up the SITL environment according to basic setup on the web. Everything was fine and working, but the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found