Closed OldManMeta closed 1 year ago
Considering there are live games and products out there that use trimeshes, you are doing something wrong. I have not studied your code, but I noticed at least that you do not use typed arrays for trimesh generation. Follow the API documentation. Also your vertices array have many duplicate verts, which doesn't seem right.
Another issue is that you are creating a cuboid collider with 0 thickness, which is not supported:
let groundColliderDesc = RAPIER.ColliderDesc.cuboid(100.0, 0, 100.0);
@LeXXik - the vertis and indicies are correct, directly from a cube created in blender. I verified this also in Three.js. Unless your definition is different?
Considering there are live games and products out there that use trimeshes, you are doing something wrong.
I agree. Burt given the examples of how I am specify both the Trimesh and the Character Controller, it is not clear to me WHERE that issue is, as I have tried every combination of flags and settings I can find.
My code is taken directly from your docs:
//Player Controller
let offset = 0.01;
let characterController = world.createCharacterController(offset);
// Enable the automatic application of impulses to the dynamic bodies
// hit by the character along its path.
characterController.setApplyImpulsesToDynamicBodies(true);
// Don’t allow climbing slopes larger than 45 degrees.
characterController.setMaxSlopeClimbAngle((45 * Math.PI) / 180);
// Automatically slide down on slopes
characterController.setMinSlopeSlideAngle((10 * Math.PI) / 180);
// Autostep if the step height is smaller than 0.5, its width is larger than 0.2,
// and allow stepping on dynamic bodies.
characterController.enableAutostep(0.7, 0.3, true);
// Snap to the ground if the vertical distance to the ground is smaller than 0.5.
characterController.enableSnapToGround(0.7);
Dynamic objects collide with the Trimesh correctly. The Kinematic Character Controller does not. That sort of points to that as potentially the issue does it not?
The Trimesh generates correctly - the world object shows it. So if it's wrong, then you just found another bug, because the world should reject it. The arrays should also cause an error if they are not typed correctly.
The link above is to a codesandbox that is JS.
My server version is TypeScript.
This is how the arrays are specified:
var vertArray: Float32Array = new Float32Array(testModel.trimeshVertices);
var indiArray: Uint32Array = new Uint32Array(testModel.trimeshIndicies);
While I really appreciate your help, I would ask you to kindly stop telling me to follow the documentation. I have read the docs over and over for so many areas. The documentation is great, but it is also not consistent between RUST and JS.
@sebcrozet - thank you for letting me know about the cuboid. Can you show me in the docs where that is stated as I must have overlooked it - though I do not understand how that could impact the character controller or the trimesh?
While I really appreciate your help, I would ask you to kindly stop telling me to follow the documentation. I have read the docs over and over for so many areas. The documentation is great, but it is also not consistent between RUST and JS.
Referring to the doc is often the correct first step towards fixing an issue, so it’s a great first advice. Also note that you should read the javascript user-guide, not the rust one (I’m just clarifying it since you mentioned inconsistency between rust and JS).
Sometimes the doc is lacking in some areas, so it’s good that you mention what you tried from reading it. For example, yeah, it’s is not mentioned that a cuboid (or any shape with a volume) must not have a 0 width.
I suggest that you modify your code-sandbox to add a character controller that shows the problem. As-is, we can’t see what’s wrong in the code.
@sebcrozet @LeXXik - guys, let me first say thank you for all your helpful points and responses both in here and on Discord. If I've not stated it already, I think this project is just totally awesome. I've used several other engines, and Rapier is out in front by a long shot.
I wanted to do a PR for the 0 width, but I seriously do not understand RUST, and the code implementation between it and JS is super impressive, but outside my areas of expertise.
When it comes down to it - I 100% believe it is my interpretation of the docs that is tripping me up here - specifically the mental model of the Character Controller being a detached tool.
I will continue to make some changes this evening and update the CSB failing any wins.
Cheers
Ah, I am not related to the development of Rapier. Seb is the man here. I'm just a user, like you are. The example project you listed was using default JS arrays, not the typed ones, hence me referring to the API.
The result here was some hand-holding to structure correctly, along with a proposed name change to give clarity to the computed result function parameters. Thanks again!
The following codesandbox shows a simple cube in the centre of the world, with a ball moving towards it. The ball will collide correctly, but when I place a character controller in this, it will just walk straight through the trimesh - the character controller will still hit the ball though.
I've verified this on a client version, with different body/collider pairs, but regardless the Kinematic Character Controller.
https://codesandbox.io/p/sandbox/rap3-trimesh-no-collision-iretsk?file=%2Findex.js
Any insight into this would be amazing. I have not found anyone else having success with Trimesh as a collider, but it must work as the R3F/Rapier wrapper implements it and it works in that library. Having reviewed that source code, I am not able to determine what it is that they are doing different, though I do recall using a customer controller that was based on a dynamic body.
I would love the answer to be that I have not set something on either of the colliders/bodies - if that is the case, then documentation may need additions.
Changing the collider type to ConvexHull is not an option for me, so is not an answer that works.
Version is Compat 0.11.2