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

deltaTime parameter in Body#update does not work as expected. #1180

Open
Andrek25 opened this issue Nov 23, 2022 · 3 comments
Open

deltaTime parameter in Body#update does not work as expected. #1180

Andrek25 opened this issue Nov 23, 2022 · 3 comments

Comments

@Andrek25
Copy link

I'm doing this:

const vector = Vector.create(400, 0);
Body.setVelocity(body, vector);
const deltaTime = 500;
Body.update(body, deltaTime, 1, 1); // body, deltaTime, scaleTime, correction;

I'm assuming that passing 500ms in the deltaTime my body will get 200px moved to the right, but it does not matter if i use 1 billion ms or -1ms, it keep moving 400px exactly, so i'm interpreting that parameter badly?

Body.update(body, 16.6, 1, 1);
image
image

Body.update(body, 500, 1, 1);
image
image

@liabru
Copy link
Owner

liabru commented Nov 26, 2022

Up to and including the release 0.18.0 velocity and speed units are (effectively) pixels per deltaTime ms which I think is what you're seeing, for these versions: normalise the result if not using a fixed deltaTime.

Note: this is due to become built in among other changes as part of #777 so please track that and keep an eye on release notes.

@Andrek25
Copy link
Author

Sorry i don't get it 😅
If the movement is effectvely why the deltaTime literally do anything:

// If i'm passing a higher number in the `deltaTime` parameter.
console.log(Number.MAX_SAFE_INTEGER); // => 9007199254740991

// WHY this is moving the body how it's running at `1000 / 60`?
Body.update(circle, Number.MAX_SAFE_INTEGER, 1.0, 1.0);

So i don't understand why MatterJS is fixing internally the deltaTime or whatever is happening with the Verlet integration.

Maybe i need to use Engine.update but i just want to move a body that was in the past to the present, so i need to simulate it for a higher deltaTime and i don't want to call multiple times the update function in 1 tick, can you help me with a simple example of this if it's not hard please 🙏🏻.

@liabru
Copy link
Owner

liabru commented Mar 15, 2023

I'm not quite sure but worth trying out the latest release 0.19.0 as that includes #777, which has some changes related to this topic that might help.

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

2 participants