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

Strange KinematicCharacterControllerOutput behaviour #377

Open
Pyroglyph opened this issue May 31, 2023 · 2 comments
Open

Strange KinematicCharacterControllerOutput behaviour #377

Pyroglyph opened this issue May 31, 2023 · 2 comments
Labels
A-Dynamics A-Integration very bevy specific C-Bug Something isn't working D-Medium P-High arbitrary important item S-not-started Work has not started

Comments

@Pyroglyph
Copy link

Sorry for the vague title, I'm really not sure how to word this succinctly.

I'm trying to make a basic 2D character controller with gravity and collisions. For this, I decided to use the provided KinematicCharacterController and Velocity components to handle collisions and movement respectively.

I don't know if it's something I've done wrong, but grounded keeps flickering between true and false every couple of frames if I reset linvel.y while not grounded, even when the player collider is nowhere near the ground collider. If you wait for it to fall through, it no longer flickers.

I've put together a gist that illustrates the problem.
If you Check the console you'll find something like this repeated over and over:

Grounded: true	Velocity: [0, 0]
Grounded: false	Velocity: [0, 0]
Grounded: false	Velocity: [0, -9.81]
Grounded: false	Velocity: [0, -19.62]
Grounded: false	Velocity: [0, -29.429998]
Grounded: true	Velocity: [0, -39.239998]

If you remove Line 47 (the line resetting linvel.y), the flickering stops, but the colliders still pass through each other instead of colliding.

Extra notes:

  • I've noticed that if I set linvel.y to a negative value (down) instead of resetting it to zero, grounded stops flickering when the player reaches the ground, but then slowly sinks down into it.
  • The issue also happens when using a fixed timestep, if that helps.
  • The issue still happens when using the Ccd component.
  • KinematicCharacterController.snap_to_ground does nothing to help.

Am I doing something wrong? I thought something like setting the Y velocity to 0 when on the floor would be a relatively simple thing to do.

@phenax
Copy link

phenax commented Jul 26, 2023

Facing the exact same issue here. Anyone looking into this?

@spoorn
Copy link

spoorn commented Aug 15, 2023

I see the same thing in 3D as well. The only force I'm applying to the entity is gravity downward, but it flips between true/false for grounded every frame even though the entity's Transform is unchanged:

grounded KinematicCharacterControllerOutput { grounded: false, desired_translation: Vec3(0.0, 0.0, 0.0), effective_translation: Vec3(0.0, 0.0, 0.0), collisions: [] }
character NOT grounded pos Vec3(-10.0, 0.0, 16.47299)
 grounded KinematicCharacterControllerOutput { grounded: true, desired_translation: Vec3(0.0, 0.0, -10.0), effective_translation: Vec3(0.0, 0.0, 0.0), collisions: [CharacterCollision { entity: 48v0, character_translation: Vec3(-10.0, 0.0, 16.47299), character_rotation: Quat(0.0, 0.0, 0.0, 1.0), translation_applied: Vec3(0.0, 0.0, 0.0), translation_remaining: Vec3(0.0, 0.0, -10.0), toi: Toi { toi: 0.69120264, witness1: Vec3(-10.162319, -0.40132886, 15.116304), witness2: Vec3(-0.1623106, -0.40130597, -0.6654587), normal1: Vec3(0.26897535, 0.6691901, 0.6927026), normal2: Vec3(-0.26897535, -0.6691901, -0.6927026), status: Converged } }] }
character grounded pos Vec3(-10.0, 0.0, 16.47299)

The only difference is it has some collisions when grounded = true, but I don't apply any forces and the entity's position is unchanged

@Vrixyz Vrixyz added C-Bug Something isn't working D-Medium P-High arbitrary important item S-not-started Work has not started A-Dynamics A-Integration very bevy specific labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dynamics A-Integration very bevy specific C-Bug Something isn't working D-Medium P-High arbitrary important item S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

4 participants