chandlerprall / Physijs

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

capsule tilts and falls! how to disable tilt if you move? #275

Open accncc opened 8 years ago

accncc commented 8 years ago

capsule tilts and falls! how to disable tilt if you move?

                    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);

Move: objectToEdit.setLinearVelocity({x: objectToEdit.getLinearVelocity().x, y: objectToEdit.getLinearVelocity().y, z: objectToEdit.getLinearVelocity().z + 25}) `

the capsule tilts and falls! how to disable tilt if you move?

accncc commented 8 years ago

answer

objectToEdit.setAngularFactor(new THREE.Vector3(0,0,0));