So, this is weird, I have been slowly implementing the movement system from the PointerLockControls example to better understand it and customize it along the way to fit my requirements. This is where I just gave up - the raycaster seems to be detecting some invisible object above the actual object. - Imagine you have a floor, it is located at 0, 0, 0 and is of sizes 50, 5, 50. Lets say the camera is at 0, 15, 0, I raycast below the camera to see if “there is ground”. In case there is, it allows jumping. Weird things came into play here. When you would just casually jump, you would NOT land on the original object, rather a bit (maybe 5 units) above it. When tinkering with the far and near properties of raycaster, it seemed to affect where you would land. Here are pieces of my code, hope I described the issue well enough.
var raycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 0, - 1, 0 ), 0, 10);
raycaster.ray.origin.copy(x.PointerLockControls.getObject().position);
raycaster.ray.origin.y -= 3;
var intersections = raycaster.intersectObjects(x.scene.children, false);
x.intersections = intersections;
const onObject = intersections.length > 0;
and
if(onObject) {
x.velocity.y = Math.max( 0, x.velocity.y );
x.canJump = true;
}
x.PointerLockControls.getObject().position.y += (x.velocity.y * delta);
if (x.PointerLockControls.getObject().position.y < 0) {
x.velocity.y = 0;
x.PointerLockControls.getObject().position.y = 0;
x.canJump = true;
}