Unable to set a value in BulletPhysics for HL targets


So, yet again I face issues with regards to HL specific code.


In Bullet Physics, SoftBodies and RigidBodies have different world gravity. So, if a soft body is present in a scene, I need to set the world gravity at two different locations by code. One for RigidBodyWorld and the other for SoftBodyWorld.

The Problem:

I am unable to set this value(my gravity) to a specific variable(SoftBodyWorld gravity). That is, the value of the SoftBodyWorld gravity remains the same as before. However, no errors during compile time or runtime.

After debugging the code in native C, I see that the value is indeed being set, but immediately after being set, the same value is reverted back to its original. Hence no actual changes made.

The same value, when set for JS targets, works perfectly.

My code:

//gravity: Vec4
var softSolver = new bullet.Bt.DefaultSoftBodySolver();
world = new bullet.Bt.SoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration, softSolver);

var vec1: bullet.Bt.Vector3 = null;


var worldInfo = world.getWorldInfo();
#if js
       worldGravity = worldInfo.set_m_gravity(vec1); //Works as expected
       worldInfo.m_gravity.setValue(gravity.x, gravity.y, gravity.z); //Does not work


The IDL definitions:
The value I like to set: m_gravity

CPP definitions:
The function used to set the gravity: set_m_gravity

Corresponding Bt.hx function: set_m_gravity()

Any insight on why this might be the case would be very helpful.

1 Like

Most likely, Iā€™m wrong and say stupidity, but maybe the place is here:

The same value is set for world.getWorldInfo() and world.setGravity(). And as I understand it, different values are needed.

1 Like

Hi @E1e5en, Thanks for the reply.

I may have not been clear enough. Sorry about that.

What I needed was to set the same gravity to two different attributes. So, in the code you linked, that is exactly what is happening. However, the JS code at L137 works as expected and HL code at L139 does not.

Say, if I were to trace out the values immediately before and after setting gravity like so:

//Vec1 = 0, 0, -9.81
#if js

trace(world.getWorldInfo().get_m_gravity()); // 0, -10, 0
trace(world.getWorldInfo().get_m_gravity()); // 0, 0, -9.81
//Value changed successfully


trace(world.getWorldInfo().m_gravity()); // 0, -10, 0
world.getWorldInfo().m_gravity = vec1;
trace(world.getWorldInfo().m_gravity()); // 0, -10, 0
//Value did not change


Best regards,

1 Like