Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysicsCharacter.onGround() is unreliable #18

Closed
stephengold opened this issue May 28, 2022 · 7 comments
Closed

PhysicsCharacter.onGround() is unreliable #18

stephengold opened this issue May 28, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@stephengold
Copy link
Owner

stephengold commented May 28, 2022

I saw strange character behaviors while writing tutorials for LBJ. Most of the time PhysicsCharacter.onGround() returns the correct value, but occasionally it returns true when the character is unsupported.

This allows jumping to unlimited height in tests such as HelloWalk, TestPhysicsCharacter, and TestQ3.
It might be related the character's vertical velocity being nearly zero.

@stephengold
Copy link
Owner Author

Interesting that the issue doesn't appear in HelloCharacter.

@stephengold
Copy link
Owner Author

It appears in HelloGhost, but not if I configure the character's gravity to 59.9 psu/sec2 instead of 60.
And note that HelloCharacter uses the default gravity, which is 29.4 psu/sec2.

@stephengold
Copy link
Owner Author

Sure enough:

bool btKinematicCharacterController::onGround() const
{
	return (fabs(m_verticalVelocity) < SIMD_EPSILON) && (fabs(m_verticalOffset) < SIMD_EPSILON);
}

@stephengold
Copy link
Owner Author

btKinematicCharacterController is chock full of thoughtless hacks and copypasta. It could benefit greatly from a complete rewrite. But not today! The less I modify it, the happier I'll be. Ideally, I'd simply add an isOnGround() method to the jmeKcc subclass and invoke that in place of btKinematicCharacterController::onGround().

btKinematicCharacterController contains a few protected fields that seem relevant:

  • m_wasOnGround is unfortunately set using the existing onGround() method, so no help there.
  • full_drop has the opposite sense of onGround(). Unfortunately it is updated only if m_verticalVelocity <= 0.0, so it's not useful during the rising half of a jump.
  • m_wasJumping has the opposite sense of onGround().

Of those 3 fields, m_wasJumping seems closest to providing the desired functionality. I've run a few tests, and it looks good.

@stephengold
Copy link
Owner Author

Okay, the fix is in Libbulletjme v14.5.0. In hindsight, I wish I'd made it return onGround() && !m_wasJumping;---less risk of a false positive that way.

@stephengold
Copy link
Owner Author

As written, TestPhysicsCharacter, TestQ3, and TestWalkingChar do not invoke onGround()---they permit jumping even when the character is airborne. In order to test this fix, those apps need minor modifications

@stephengold stephengold added the bug Something isn't working label May 29, 2022
@stephengold
Copy link
Owner Author

There's an issue with the current solution because it returns true after the character steps off the supporting surface. See the Forum discussion: https://hub.jmonkeyengine.org/t/linear-velocity-inconsistency-on-collisionlistener/47446/4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant