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

Engine's speed changes with object's size #889

Closed
stathismor opened this issue Jun 18, 2020 · 3 comments
Closed

Engine's speed changes with object's size #889

stathismor opened this issue Jun 18, 2020 · 3 comments
Labels

Comments

@stathismor
Copy link

stathismor commented Jun 18, 2020

I've noticed that when increasing the size of the canvas and the assets by a certain factor, the matterjs engine runs slower. For instance having a canvas of 800x400 will have its objects running faster than a 1600x800 canvas with it objects doubled in size.

I've modified an example from somewhere else, you can see what I am saying by dropping the ball in a 800x400 canvas https://codepen.io/strahius/pen/YzwNyQg and a 1600x800 canvas https://codepen.io/strahius/pen/JjGEYNB. In the 1600x800 canvas, the ball bounces slower and becomes immobile later than the 800x400 one.

Is this behaviour expected, considering that proportionally it's the same scene? Am I missing a parameter I should also scale when scaling the canvas and all objects? Is there a way to have those two versions run with the same speed?

Edit: Looks like the canvas size does not play any role in the physics calculation. If in the above examples you set the balls with the same size, they behave the same. Size is somehow affecting velocity though, in a way I cannot understand. I think I have the same issue with #833, but no value of frictionAir seems to make the objects behave the same.

@stathismor stathismor changed the title Engine's speed changes with resolution Engine's speed changes with object's size Jun 21, 2020
@liabru
Copy link
Owner

liabru commented Sep 12, 2020

Looks like you figured it out, but yes that difference is because you are using bodies of different sizes (so therefore also area, mass and density) which is why friction acts differently on them both.

If you just need to draw at a higher resolution you should handle that scaling in your drawing code instead of changing any physics code, hopefully that is what you mean?

@stathismor
Copy link
Author

To give some context, I am making a game, and at some point I decided to double the size of the resolution (and therefore of all of the assets). It's a physics based game, and I did not want to re-calibrate all the little things that affect how it works. So, as I workaround, I changed the time scale of every object. This seems to do the job, although it's not the cleanest solution.

@liabru
Copy link
Owner

liabru commented Sep 16, 2020

Thanks, then I'll assume you've got what you need, but as a reference for others I'd recommend scaling your rendering instead using graphics transforms. If you're using the built in renderer then check out the pixelRatio, width, height options as well as the function Render.lookAt as they should be able to do this for you.

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

2 participants