-
Got a real weird one, I have a simple CharacterVirtual which is pretty much copied from the Jolt Samples app: float CharacterHeightStanding = 1.35f;
float CharacterRadiusStanding = 0.3f;
StandingShape = JPH::RotatedTranslatedShapeSettings(JPH::Vec3(0, 0.5f * CharacterHeightStanding + CharacterRadiusStanding, 0), JPH::Quat::sIdentity(), new JPH::CapsuleShape(.5f * CharacterHeightStanding, CharacterRadiusStanding)).Create().Get();
Settings = new JPH::CharacterVirtualSettings();
Settings->mMaxSlopeAngle = JPH::DegreesToRadians(45.0f);
Settings->mMaxSlopeAngle = sMaxSlopeAngle;
Settings->mMaxStrength = sMaxStrength;
Settings->mShape = StandingShape;
Settings->mBackFaceMode = sBackFaceMode;
Settings->mCharacterPadding = sCharacterPadding;
Settings->mPenetrationRecoverySpeed = sPenetrationRecoverySpeed;
Settings->mPredictiveContactDistance = sPredictiveContactDistance;
Settings->mSupportingVolume = Plane(Vec3::sAxisY(), -CharacterRadiusStanding); // Accept contacts that touch the lower sphere of the capsule
PhysicsCharacter = new JPH::CharacterVirtual(Settings, JPH::RVec3::sZero(), JPH::Quat::sIdentity(), 0, PhysicsSystem);
PhysicsCharacter->SetListener(this); and a box for the character to stand on: auto Floor = BodyInterface.CreateBody(BodyCreationSettings(new JPH::BoxShape(JPH::Vec3(0.5f * 300, 1.0f, 0.5f * 300), 0.0f), JPH::RVec3(JPH::Vec3(0.0f, -1.0f, 0.0f)), JPH::Quat::sIdentity(), JPH::EMotionType::Static, physics::Layers::NON_MOVING));
auto BodyID = Floor->GetID();
BodyInterface.AddBody(BodyID, EActivation::DontActivate); and for some reason it seems to collide with the center of mass instead of the bottom of the capsule? Collision is working fine as it's triggering the ContactListener implementations for the character, yet it seems to be colliding with the center of mass? I've tried changing the Debug render code is again, the same from the CharacterVirtual sample app: JPH::RMat44 CenterOfMass = PhysicsCharacter->GetCenterOfMassTransform();
auto CharShape = Character.Character->PhysicsCharacter->GetShape();
CharShape->Draw(DebugRenderer.get(), CenterOfMass, JPH::Vec3::sReplicate(100.0f), Color::sGreen, true, true); Yet in the Jolt Samples app the CharacterVirtual clearly stands on top of the ground normally. Any thoughts on how further to debug or fix are appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Oddly, I was able to get it to work if I updated the shape using
|
Beta Was this translation helpful? Give feedback.
-
I'm not really sure what I'm looking at. How are you drawing the box? If I look at the screenshot, it looks like the character is standing perfectly on the floor of your level but it appears that the box (assuming this represents the floor) is being drawn in the wrong spot? Note that the center of mass of the character is the center of the capsule, so PS1. In your use of |
Beta Was this translation helpful? Give feedback.
The way you draw the world is correct. Now that you're mentioning that this is in Unreal it makes a lot more sense. Unreal uses cm units while Jolt uses meter units, so you probably tried to correct for this using:
CharShape->Draw(..., JPH::Vec3::sReplicate(100.0f), ...);
However, scaling a shape in Jolt always works in local space of the shape (from the center of mass in this case), so what you're (most likely) doing is passing a GetCenterOfMassTransform() that contains an offset in meters and scaling the shape from its center of mass by a factor 100. That means that the translation in the center of mass is a factor 100 too small and it appears that the capsule is with its center on the …