I mean is it 1 pixel per millisecond or what. When I apply a force of "1" to a shape it moves so fast that it disappears from the canvas! Even if it hits a static shape like a floor, it seems to penetrate through. I always have to use decimals with Matter.Body.applyForce. But now I need to create a functionality where enough vertical force is calculated and applied so that the shape reaches the same height from its current position as my cursor so I really need this.
Also when gravity is set to 0, how much downward force and how often (like in a setInterval()) do I need to give a shape to produce the same amount of downward acceleration as gravity 1?
Yeah, the context of these values in the documentation is something I've struggled with.
Most things seem to expect a value of 0 to 1, though what "1" means is kind of ambiguous.
Applying a force is not the same as just setting velocity, the result depends on:
Also consider:
Most things seem to expect a value of 0 to 1, though what "1" means is kind of ambiguous.
Not sure what you mean, this isn't the case with any functions I can think of?
Matter.Body.applyForce() is kind of vague on what sort of values it expects as a vector. Like, right now, I try to apply it to a Matter.Bodies.circle() with a radius of 15 in a Matter.World with 0 gravity, and every frame of a game I'm applying a vector of (0.0005, 0.0005) if a gamepad is pressing direction buttons to move it vertically and horizontally. And I'm not really sure what that means to be honest? But it takes that small amount of force to just move it at a rate of I dunno, something like 100 pixels a second. If I applied a force anywhere close to (1, 1) on that object, it would fly off screen immediately. So I'm not sure what "1" means in that scenario, I have no baseline.
As for other ranges of 0 to 1, well, I was using Matter.Composites.chain() and it took me ages to figure out what the offset parameters are. It seems like 1 corresponds to the absolute height or width of the composite's bounding boxes? I gave up using it and made a chain myself because it took so long to figure out and didn't fit my use case.
A constraint stiffness appears to max out at 1, but that's not too crazy. Though if it doesn't max out at 1, I'm not sure what over 1 would imply.
I was using Matter.Bodies.trapezoid() and it appeared the "slope" argument maxed out at 1 as a triangle before exhibiting weird behaviour (side note: it's really annoying how adjusting the slope argument messes up the height).
Looking at the demo page, a few other values max out at 1 on the sliders, like restitution, friction, x and y gravity. Some of the other values there max out at weird values like 0.001, 0.01, 0.1, and 10 (?), with no context, so it's hard to conceptualize what they mean. And since most of those values are under 1, and values over 1 usually cause odd behaviour, I just started assuming that was a normal pattern? Is it not?
It just takes a vector of any magnitude, the result of the force depends on the mass of the body you apply it to (among the other things above). Note that the signature is Matter.Body.applyForce(body, position, force) too where the position is in world-space. In your case it sounds like you should use the body centre of mass e.g. Matter.Body.applyForce(body, body.position, force) which means there will be no rotation too.
I think if you want to make the force seem 'constant' for all bodies (like gravity) then you should multiply it by the body's mass first e.g. Matter.Body.applyForce(body, body.position, Vector.multiply(force, body.mass)). Either way, often forces are not the best solution and instead you should directly control velocity instead like in the body manipulation example.
As for other ranges of 0 to 1, well, I was using Matter.Composites.chain() and it took me ages to figure out what the offset parameters are.
Yeah the docs are lacking here, but you're right that's how it works.
A constraint stiffness appears to max out at 1, but that's not too crazy. Though if it doesn't max out at 1, I'm not sure what over 1 would imply.
Sort of. It's possible to use values over 1 but it will quickly become more unstable. The reasons why are not straightforward to explain though!
Looking at the demo page, a few other values max out at 1 on the sliders, like restitution, friction, x and y gravity. Some of the other values there max out at weird values like 0.001, 0.01, 0.1, and 10 (?),
These are really just chosen as 'sane' values through trial and error. That's really what it comes down to in many cases because there are so many variables combined with limited stability ranges. Also some concepts can be a bit counter-intuitive by nature, especially when it comes to friction. Game engines usually do a lot of work to make these things easier to use!
Thanks, that's actually some good insight. Hopefully it helps the author of this issue as well.
I'll experiment with velocity.
The reason this happens is because the force calculation uses deltaTime which is in milliseconds rather than seconds. So https://github.com/liabru/matter-js/blob/master/src/body/Body.js#L639 is multiplying by milliseconds squared rather than seconds squared. In order to correct for this, you should divide your forces by 1,000,000
Most helpful comment
The reason this happens is because the force calculation uses deltaTime which is in milliseconds rather than seconds. So https://github.com/liabru/matter-js/blob/master/src/body/Body.js#L639 is multiplying by milliseconds squared rather than seconds squared. In order to correct for this, you should divide your forces by 1,000,000
See issue https://github.com/liabru/matter-js/issues/855