Hello,
I am trying to upgrade to the bjs v5 and the ammo physics seems to behave different. I have a mesh moving in the space. When I apply for example thrust force I want it to be applied always from its relative local back side. In the v4.2 I did that using these simple functions:
var vmult = function(v,q){
var target = new BABYLON.Vector3();
var x = v.x,
y = v.y,
z = v.z;
var qx = q.x,
qy = q.y,
qz = q.z,
qw = q.w;
// q*v
var ix = qw * x + qy * z - qz * y,
iy = qw * y + qz * x - qx * z,
iz = qw * z + qx * y - qy * x,
iw = -qx * x - qy * y - qz * z;
target.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
target.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
target.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
return target;
};
var vectorToWorldFrame = function(localVector, quaternion){
var result = new BABYLON.Vector3();
result = vmult(localVector, quaternion);
return result;
};
var pointToWorldFrame = function(localPoint,quaternion, position){
var result = new BABYLON.Vector3();
result = vmult(localPoint,quaternion);
result = result.add(position);
return result;
};
var applyLocalForce = function(localForce, localPoint, mesh){
var worldForce = new BABYLON.Vector3();
var worldPoint = new BABYLON.Vector3();
// Transform the force vector to world space
worldForce = vectorToWorldFrame(localForce, mesh.rotationQuaternion);
worldPoint = pointToWorldFrame(localPoint, mesh.rotationQuaternion, mesh.getAbsolutePosition());
mesh.physicsImpostor.applyForce(worldForce, worldPoint);
};
It worked in v4.2 but its spinning like crazy in the v5. I dont have a playground yet as it is in a larger repo. I will try to create something simple to demonstrate the issue. Maybe there is something obvious to spot?