Birch-san / box2d-wasm

Box2D physics engine compiled to WebAssembly. Supports TypeScript and ES modules.
263 stars 21 forks source link

b2_maxTranslation #10

Closed hutzlibu closed 3 years ago

hutzlibu commented 3 years ago

Box2D has a max velocity setting. Which is also does not recommend to mess with, but I want to, but can't find the property in your port.

b2_maxTranslation and b2_maxTranslationSquared are the properties I am looking for to change them. Maybe they got hardcoded into WASM?

Birch-san commented 3 years ago

https://github.com/erincatto/box2d/blob/master/include/box2d/b2_common.h#L95-L96

They're compile-time constants, so yeah they get inlined into the WASM at the time I build a release.

They're ultimately used in two places in the Box2D source code:

https://github.com/erincatto/box2d/blob/master/src/dynamics/b2_island.cpp#L289-L291
https://github.com/erincatto/box2d/blob/master/src/dynamics/b2_island.cpp#L487-L489

In the original Box2D, changing these would require you to modify the C++ source code and compile your own bespoke release. The same applies to box2d-wasm; there's no function that I can expose via JS to make this configurable.

Do you have the option of calculating more velocity/position iterations in your timestep? Or maybe making objects 10x smaller but rendering them 10x bigger?

hutzlibu commented 3 years ago

there's no function that I can expose via JS to make this configurable.

I don't know about the build process, but if its too hard to expose it, then it is not something urgent needed now. Maybe in the future adding a getter/setter by hand or something like that. It is not recommended in the first place after all. (and increasing it to a value like 4 made the world sometimes very glitchy)

But I am already at the size limit. Box2D states somewhere that the smallest recommended size is 0.1 m for world objects. But for now, yes, I can adjust iterations. And rework some of the involved forces/impulses.

Right now my projectiles flying the same speed as the fastest player (so shooting while moving causes bullets to not fly away) but this is something I have to rework.