gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.5k stars 261 forks source link

CharacterMovement Example: Prevent character from sliding down stairs, ramps #251

Closed gkjohnson closed 3 years ago

gkjohnson commented 3 years ago

Related to #247

The capsule collider being adjusted by all triangles on the stairs results in the character being pushed to the side, then sunk by gravity, then pushed to the side, etc. It results in the character slowly sliding down the stairs. An improvement would be to not slide down corners at all or sliding more quickly so it's not as visually intrusive. The sliding behavior would likely also happen down ramps.

makc commented 3 years ago

you have this: https://github.com/gkjohnson/three-mesh-bvh/blob/master/example/characterMovement.js#L420-L435 then maybe you should only do player.position.copy( newPosition ); inside of if ( ! playerIsOnGround ) { ?

gkjohnson commented 3 years ago

then maybe you should only do player.position.copy( newPosition ); inside of if ( ! playerIsOnGround ) { ?

Thanks for taking a look @makc! Unfortunately if you only apply the new adjusted position from the collisions if the player is seen as "on the ground" then the player will start to sink through the floor because the collision adjustment from the ground isn't applied.

@vin-ni I took a bit of a look at it and came up with a relatively simple fix for the sliding issue in #252. I've updated the example build on master so take a look and see if that fixed it for you.

vin-ni commented 3 years ago

Thanks, I'll take a look.

gkjohnson commented 3 years ago

Gonna close this for now -- feel free to ping or open a new issue if there's still an issue @vin-ni!

vin-ni commented 3 years ago

Works for now! Thank you!