Hello, I know the title is extremely weird but let me explain myself:
I am creating a PointerLockControls powered movement engine with collision detection, but I have no idea how to compensate for this little issue:
Since I want it to be used with 3D games, the camera is in some height, which means I need to make sure that the camera does not pass through objects in movement direction, for which I of course use raycaster, casted into the required directions attached to the camera, which means that it only detects objects in the height of the camera. I need to make sure that an object, for example lower than cameras height is being detected, same goes for any other height. I have I made it clear. Thanks for any answers in advance.
Hello everyone. I am a bit late with my solution actually as I have solved it very late the day I asked and forgot about you guys here. If anyone is looking for such an alternative, I sadly was not able to find any, but I came up with a workaround. I simply create 4 raycasters, two for each axis and point them down, in case they intersect, movement is blocked. I still have not fully figured the thing out as it needs to adjust to your camera direction but other than that it works pretty well. Here is the code in question:
var mrc2c = controls.getObject().position.clone();
/* Do not forget to increase the pos by 1, this is the part where I crashed. */
var mrc2 = new THREE.Raycaster(mrc2c, new THREE.Vector3(0, - 1, 0), 0, 12);
One common way to simplify this is to compute a “collision mesh” or “navigation mesh” (two slightly different things) derived from your rendered scene. The collision mesh is just a simplified version of the scene, possibly with heights and other shapes adjusted for raycasting or physics collisions.
A navigation mesh covers the horizontal surfaces with some padding (maybe 0.5m) around obstacles. That way you can always raycast directly down onto the navmesh, or use something like three-pathfinding’s clampStep(...) method for FPS controls, and it stops the camera just before hitting walls.