Skip to content

Kinematic character controller dips and can eventually fall through moving vertical platform #488

Open
@robertlong

Description

@robertlong

When standing on top of a vertically moving platform, the kinematic character controller doesn't stay stuck to the platform. Instead it kind of bounces and dips into the platform. This can be observed here:

VerticalPlatform.mp4

If you constantly move while standing on top of the platform, this bouncing effect is canceled out:

VerticalPlatformConstantlyMoving.mp4

And sometimes you can fall through the platform entirely:

VerticalFallThrough.mp4

This example uses Rapier.js but I don't think this is specific to the WASM version.

Here's our character controller settings:

const characterController = physicsWorld.createCharacterController(0.1);
characterController.enableAutostep(0.7, 0.3, true);
characterController.enableSnapToGround(0.3);
characterController.setCharacterMass(100);
characterController.setApplyImpulsesToDynamicBodies(true);
characterController.setSlideEnabled(true);

And here you can see where we compute the character controller position:
https://github.com/matrix-org/thirdroom/blob/e4c1a24a21e6d7300c7dabc5055b93ed6847ac3a/src/plugins/KinematicCharacterController.ts#L263

The platform is a kinematic rigid body (RAPIER.RigidBodyDesc.kinematicPositionBased()) which is moved using: body.setNextKinematicTranslation(_v)
https://github.com/matrix-org/thirdroom/blob/e4c1a24a21e6d7300c7dabc5055b93ed6847ac3a/src/engine/physics/physics.game.ts#L239

Here's the example live, you'll need at least a guest account to view it:
https://deploy-preview-599--thirdroom.netlify.app/world/#websg-v1-dev:thirdroom.io

You can also see this live in another example using Rapier and react-three-fiber:
https://game-sandbox.vercel.app/
https://github.com/alexandernanberg/sandbox

Screen.Recording.2023-05-03.at.6.27.06.PM.mp4

@NateTheGreatt and I have looked at the code in the Rust implementation of the character controller and tried tweaking things. However, we're not exactly sure where to look. We're happy to help fix the issue but could use some help figuring it out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2DThe issue is specifically about the 2D version of Rapier.3DThe issue is specifically about the 3D version of Rapier.A-DynamicsC-BugSomething isn't workingD-DifficultP-Medium

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions