jrouwe / JoltPhysics.js

Port of JoltPhysics to JavaScript using emscripten
MIT License
246 stars 19 forks source link

about gravity #124

Closed lo-th closed 6 months ago

lo-th commented 6 months ago

Hi i need change gravity of one object in simulation.

is possible on BodyCreationSettings with bcs.mGravityFactor = 0.5;

but after creation of body is not possible to change gravityfactor

DennisSmolek commented 6 months ago

You can't do it on the body directly but you can by using the body interface:

https://jrouwe.github.io/JoltPhysics/class_body_interface.html#a2171a36d0ff2b98c019ed4b0bcb0db39

So something like: this.bodyInterface.SetGravityFactor(BodyId, 3);

It's been a hard habit to break for me but I'm learning that with Jolt many methods aren't on the object directly but managed through interfaces/systems/managers.

lo-th commented 6 months ago

ok thanks, i see but is seems is not exposed in js version

jrouwe commented 6 months ago

There's also MotionProperties::SetGravityFactor (so body.GetMotionProperties().SetGravityFactor(...)). I've exposed both functions in the js version now (but you need to compile it yourself since I didn't create a release).

It's been a hard habit to break for me but I'm learning that with Jolt many methods aren't on the object directly but managed through interfaces/systems/managers.

Most of the functions on BodyInterface are convenience functions that will take a lock on the body and call a function, in this case they just mirror the function on Body or MotionProperties. Some of them (e.g. setting positions) are only available through the BodyInterface as the managing systems also need to be made aware that changes happened.