few more tweaks

check for mass first in joltBody so that we set dynamic early
This commit is contained in:
marauder2k7 2026-06-07 17:32:27 +01:00
parent 174e4d3329
commit c81a809444
3 changed files with 12 additions and 11 deletions

View file

@ -70,16 +70,18 @@ bool JoltBody::init(PhysicsCollision* shape, F32 mass, U32 bodyFlags, SceneObjec
JPH::EMotionType motionType = JPH::EMotionType::Static;
JPH::ObjectLayer layer = Layers::NON_MOVING;
if (bodyFlags & BF_KINEMATIC)
{
motionType = JPH::EMotionType::Kinematic;
layer = Layers::MOVING;
}
else if (mass > 0.0f)
if (mass > 0.0f)
{
motionType = JPH::EMotionType::Dynamic;
layer = Layers::MOVING;
}
else if (bodyFlags & BF_KINEMATIC)
{
motionType = JPH::EMotionType::Kinematic;
layer = Layers::MOVING;
}
mMass = mass;
MatrixF objXfm = obj->getTransform();
@ -101,7 +103,6 @@ bool JoltBody::init(PhysicsCollision* shape, F32 mass, U32 bodyFlags, SceneObjec
settings.mOverrideMassProperties = JPH::EOverrideMassProperties::CalculateInertia;
settings.mMassPropertiesOverride.mMass = mass;
settings.mMaxLinearVelocity = 1000.0f; // stops an assert, this is torques upper limit, jolts is 500.0f by default.
mMass = mass; // FIX: was never stored, getMass() always returned 0
mIsDynamic = true;
}

View file

@ -57,6 +57,7 @@ void JoltCollision::addPlane(const PlaneF& plane)
void JoltCollision::addBox(const Point3F& halfWidth, const MatrixF& localXfm)
{
JPH::BoxShapeSettings boxSettings(JPH::Vec3(halfWidth.x, halfWidth.y, halfWidth.z));
boxSettings.mConvexRadius = 0.01f;
auto result = boxSettings.Create();
if (result.HasError())
@ -329,6 +330,9 @@ bool JoltCollision::addHeightfield(
void JoltCollision::rebuildCompound()
{
// clear
mCompundShape = nullptr;
if (mChildren.empty())
return;

View file

@ -66,10 +66,6 @@ public:
Point3F move(const VectorF& displacement, CollisionList& outCol) override;
bool _recoverFromPenetration(JPH::RVec3& inOutPos);
bool _sweep(JPH::RVec3& inOutPos, const JPH::Vec3& disp, CollisionList* outCol);
void _stepForward(JPH::RVec3& inOutPos, const JPH::Vec3& displacement, CollisionList* outCol);
void findContact(SceneObject** contactObject, VectorF* contactNormal, Vector<SceneObject*>* outOverlapObjects) const override;
bool testSpacials(const Point3F& nPos, const Point3F& nSize) const override;
void setSpacials(const Point3F& nPos, const Point3F& nSize) override;