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

ConvexPolyhedron isn't working for certain vertices #181

Open
Gartenimperator opened this issue May 10, 2023 · 0 comments
Open

ConvexPolyhedron isn't working for certain vertices #181

Gartenimperator opened this issue May 10, 2023 · 0 comments

Comments

@Gartenimperator
Copy link

Gartenimperator commented May 10, 2023

When i create a convexPolyhedron with the values:

let vertices: CANNON.Vec3[] = [
            new CANNON.Vec3(1.6914, 0.524775, 1.102675), // 1
            new CANNON.Vec3(1.7181, 0.581274, 2.075575), // 2
            new CANNON.Vec3(-4.1381, -1.222925, -4.314225), // 3
            new CANNON.Vec3(0.7285, 0.116874, 1.135975), // 4
        ];

let faces = [
[2, 1, 0],
[3, 1, 2],
[3, 0, 1],
[3, 2, 0]];

let chassisShapeComplex = new CANNON.ConvexPolyhedron({
            vertices: body,
            faces: facesNotTriangulized
        });

let chassisBody = new CANNON.Body({
            mass: this.bodyMass,
            position: new CANNON.Vec3(0, 10, 0), //cars spawn 10 meters in the air.
            material: bodyMaterial,
            collisionFilterGroup: 1,
            collisionFilterMask: 2 | 4
        });

chassisBody.addShape(chassisShapeComplex);

let trackStart = new CANNON.Body({
            mass: 0, // mass = 0 makes the body static
            material: this.groundMaterial,
            shape: new CANNON.Box(new CANNON.Vec3(10, 1, 50)),
            position: new CANNON.Vec3(0,-10,2),
            collisionFilterGroup: 2,
            collisionFilterMask: 1
        });

(rough copy paste of my code)
and drop it onto a static Box (under normal gravity 0, -9.82, 0) (here 'trackStart'), the collision isn't calculated correctly and the convexPolyhedron glitches into the box. It works if i create a compound body out of the 4 triangle faces!
I for the life of me couldn't make a jsFiddle with three.js and cannon.js working, so I hope you can reproduce the bug with this much.
I can also supply the whole project im working (on with the bug), if needed.
I'd be very grateful if someone could share some ideas, as to whats going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant