chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.77k stars 455 forks source link

Why the capsule passes through objects? #277

Open accncc opened 8 years ago

accncc commented 8 years ago

How to make so that it did not pass through objects? the probability of passage is about 95% or use a character controller to the cube?

                var merged = new THREE.Geometry();
                var cyl = new THREE.CylinderGeometry(2, 2, 6);
                var top = new THREE.SphereGeometry(2);
                var bot = new THREE.SphereGeometry(2);
                var matrix = new THREE.Matrix4();
                matrix.makeTranslation(0, 3, 0);
                top.applyMatrix(matrix);
                var matrix = new THREE.Matrix4();
                matrix.makeTranslation(0, -3, 0);
                bot.applyMatrix(matrix);
                merged.merge(top);
                merged.merge(bot);
                merged.merge(cyl);
                var capsule = new Physijs.CapsuleMesh(
                    merged,
                    new THREE.MeshBasicMaterial({color: Math.random() * 0xffffff }),
                    0.1
                );

                capsule.position.set(100, 220, 0 );
                capsule.scale.set(10, 10, 10);

                objectToEdit = capsule;

                scene.add(capsule);
accncc commented 8 years ago
                    var basis = new Physijs.SphereMesh(
                        new THREE.SphereGeometry( 30 ),
                        new THREE.MeshBasicMaterial({ color: 0x888888 }),
                        1
                    );

                    basis.character = true;
                    basis.material.transparent = true;
                    basis.material.opacity = 0.5;

                    basis.setDamping(
                        0,// linear_amount
                        0 // angular_amount
                    ); 

                    basis.position.set(80, 80, 0 );

                    objectToEdit = basis;

                    scene.add(basis);

                    var merged = new THREE.Geometry();
                    var cyl = new THREE.CylinderGeometry(2, 2, 6);
                    var top = new THREE.SphereGeometry(2);
                    var bot = new THREE.SphereGeometry(2);
                    var matrix = new THREE.Matrix4();
                    matrix.makeTranslation(0, 3, 0);
                    top.applyMatrix(matrix);
                    var matrix = new THREE.Matrix4();
                    matrix.makeTranslation(0, -3, 0);
                    bot.applyMatrix(matrix);
                    merged.merge(top);
                    merged.merge(bot);
                    merged.merge(cyl);
                    var capsule = new Physijs.CapsuleMesh(
                        merged,
                        new THREE.MeshBasicMaterial({color: Math.random() * 0xffffff }),
                        1
                    );

                    capsule.position.set(0, 16, 0 );
                    capsule.scale.set(15, 10, 15);

                    basis.add(capsule);