You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to migrate my game from p2.js to another physics engine (since p2 missescollisions and is no longer maintained) and matter-js seems to be the most popular. For trying things out, I wrote a bouncing ball simulation:
The ball falls from a height of 180 m and with gravity set to 10 m/s², it should take exactly 6 s until it hits the ground and the impact velocity should be exactly 60 m/s.
However, it reports t=0.183 v=31.94 and the ball does not bounce at all.
After a lot of experimenting and digging in documentation and code, I found that:
There is a gravity scale which defaults to 0.001 (why?)
The delta parameter in Engine.update is not in ms, it is in the same unit that I use everywhere else.
There are the internal parameters Matter.Body._baseDelta and Matter.Common._baseDelta which are set to 1000 / 60 and influence velocity set/get and frictionAir and probably also other things.
Actually I first reported body.velocity until I figured that it's not really the body's velocity but the position delta during the last step. It also says "Equivalent to the magnitude of body.angularVelocity (always positive)." in the documentation which I think is a copy-paste mistake.
And I also found this Body._inertiaScale = 4; which will probably cause a hickup at some point.
After accounting for all of this, I got it working with this code:
I want to migrate my game from p2.js to another physics engine (since p2 misses collisions and is no longer maintained) and matter-js seems to be the most popular. For trying things out, I wrote a bouncing ball simulation:
I am working with SI units for portability across engines. As far as I understand, this should work well with matter-js.
The ball falls from a height of 180 m and with gravity set to 10 m/s², it should take exactly 6 s until it hits the ground and the impact velocity should be exactly 60 m/s.
However, it reports
t=0.183 v=31.94
and the ball does not bounce at all.After a lot of experimenting and digging in documentation and code, I found that:
Engine.update
is not in ms, it is in the same unit that I use everywhere else.Matter.Body._baseDelta
andMatter.Common._baseDelta
which are set to1000 / 60
and influence velocity set/get and frictionAir and probably also other things.Actually I first reported
body.velocity
until I figured that it's not really the body's velocity but the position delta during the last step. It also says "Equivalent to the magnitude of body.angularVelocity (always positive)." in the documentation which I think is a copy-paste mistake.And I also found this
Body._inertiaScale = 4;
which will probably cause a hickup at some point.After accounting for all of this, I got it working with this code:
Why are there so many magic constants sprinkled everywhere? I have two guesses:
In case (2) is right, would it be an option to introduce some sort of useSI flag that sets all magic constants to 1?
(Also, why is there no bounce in the first version?)
The text was updated successfully, but these errors were encountered: