Skip to content

Commit

Permalink
CharacterBaseTest: solve crash when switching test scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 25, 2024
1 parent 44fe74f commit e9d9d49
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -684,32 +684,33 @@ else if (pos.yy() > cReversingVerticallyMovingPosition.yy() + 5.0f)

// Animate character virtual
for (CharacterVirtualRef character : new CharacterVirtualRef[]{ mAnimatedCharacterVirtual, mAnimatedCharacterVirtualWithInnerBody })
{
if (implementsDebugRendering())
character.getShape().draw(mDebugRenderer, character.getCenterOfMassTransform(), Vec3.sReplicate(1.0f), Color.sOrange, false, true);
else
mDebugRenderer.drawCapsule(character.getCenterOfMassTransform(), 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + character.getCharacterPadding(), Color.sOrange, ECastShadow.Off, EDrawMode.Wireframe);

// Update velocity and apply gravity
Vec3 velocity;
if (character.getGroundState() == EGroundState.OnGround)
velocity = Vec3.sZero();
if (character != nullptr)
{
if (implementsDebugRendering())
character.getShape().draw(mDebugRenderer, character.getCenterOfMassTransform(), Vec3.sReplicate(1.0f), Color.sOrange, false, true);
else
velocity = plus(star(character.getLinearVelocity() , mAnimatedCharacter.getUp()) , star(mPhysicsSystem.getGravity() , inParams.mDeltaTime));
plusEquals(velocity , star(sin(mTime) , cCharacterVelocity));
character.setLinearVelocity(velocity);

// Move character
ExtendedUpdateSettings update_settings = new ExtendedUpdateSettings();
character.extendedUpdate(inParams.mDeltaTime,
mPhysicsSystem.getGravity(),
update_settings,
mPhysicsSystem.getDefaultBroadPhaseLayerFilter(Layers.MOVING),
mPhysicsSystem.getDefaultLayerFilter(Layers.MOVING),
new BodyFilter(){ },
new ShapeFilter(){ },
mTempAllocator);
}
mDebugRenderer.drawCapsule(character.getCenterOfMassTransform(), 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + character.getCharacterPadding(), Color.sOrange, ECastShadow.Off, EDrawMode.Wireframe);

// Update velocity and apply gravity
Vec3 velocity;
if (character.getGroundState() == EGroundState.OnGround)
velocity = Vec3.sZero();
else
velocity = plus(star(character.getLinearVelocity() , mAnimatedCharacter.getUp()) , star(mPhysicsSystem.getGravity() , inParams.mDeltaTime));
plusEquals(velocity , star(sin(mTime) , cCharacterVelocity));
character.setLinearVelocity(velocity);

// Move character
ExtendedUpdateSettings update_settings = new ExtendedUpdateSettings();
character.extendedUpdate(inParams.mDeltaTime,
mPhysicsSystem.getGravity(),
update_settings,
mPhysicsSystem.getDefaultBroadPhaseLayerFilter(Layers.MOVING),
mPhysicsSystem.getDefaultLayerFilter(Layers.MOVING),
new BodyFilter(){ },
new ShapeFilter(){ },
mTempAllocator);
}

// Reset ramp blocks
mRampBlocksTimeLeft -= inParams.mDeltaTime;
Expand Down

0 comments on commit e9d9d49

Please sign in to comment.