I have a three.js scene with a big mesh as my map (exported from blender).
I load it so:
// map
var loader = new THREE.JSONLoader(true);
var thiz = this;
loader.load(
"iceworld.js"
, function(geometry, materials) {
materials[0].side = THREE.DoubleSide;
var faceMaterial = new THREE.MeshLambertMaterial( materials[0] );
//var faceMaterial = new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'ice.jpg' ), side: THREE.DoubleSide } );
mesh = new THREE.Mesh( geometry, faceMaterial );
thiz.scene.add( mesh );
}
);
I use the PointerLockControls
. Now I can walk through the map's walls because there is no collision detection.
How can I implement this? I did not find a solution in the examples and documentation.
Three.js is a graphics rendering library and does not concern collision detection. You need something different for that. Here's a few options:
Physijs.ConcaveMesh
, add a collision shape to your camera and have instant, accurate collision detection - but that's going to be slow if you have a decently complex scene.Personally, I've created an FPS game with Three.js. My level design is very regular, so I could use the grid method for player collisions, but I also wanted dynamic objects (e.g. barrels, boxes etc.) and using Physijs allowed me to integrate them too almost trivially. The wall collisions are thus handled by creating Physijs cubes to wall sections.