Skip to content

Commit

Permalink
Allow overriding the body ID of the inner body of a CharacterVirtual (#…
Browse files Browse the repository at this point in the history
…1440)

Fixes #1438
  • Loading branch information
jrouwe authored Jan 6, 2025
1 parent d34db61 commit 5ef272c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Jolt/Physics/Character/CharacterVirtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ CharacterVirtual::CharacterVirtual(const CharacterVirtualSettings *inSettings, R
BodyCreationSettings settings(inSettings->mInnerBodyShape, GetInnerBodyPosition(), mRotation, EMotionType::Kinematic, inSettings->mInnerBodyLayer);
settings.mAllowSleeping = false; // Disable sleeping so that we will receive sensor callbacks
settings.mUserData = inUserData;
mInnerBodyID = inSystem->GetBodyInterface().CreateAndAddBody(settings, EActivation::Activate);

const Body *inner_body;
BodyInterface &bi = inSystem->GetBodyInterface();
if (inSettings->mInnerBodyIDOverride.IsInvalid())
inner_body = bi.CreateBody(settings);
else
inner_body = bi.CreateBodyWithID(inSettings->mInnerBodyIDOverride, settings);
if (inner_body != nullptr)
{
mInnerBodyID = inner_body->GetID();
bi.AddBody(mInnerBodyID, EActivation::Activate);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions Jolt/Physics/Character/CharacterVirtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class JPH_EXPORT CharacterVirtualSettings : public CharacterBaseSettings
/// - Fast moving objects of motion quality LinearCast will not be able to pass through the CharacterVirtual in 1 time step
RefConst<Shape> mInnerBodyShape;

/// For a deterministic simulation, it is important to have a deterministic body ID. When set and when mInnerBodyShape is specified,
/// the inner body will be created with this specified ID instead of a generated ID.
BodyID mInnerBodyIDOverride;

/// Layer that the inner rigid body will be added to
ObjectLayer mInnerBodyLayer = 0;
};
Expand Down

0 comments on commit 5ef272c

Please sign in to comment.