Raycaster hits invisible object?

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

Raycaster honors invisible objects since r114 . Please use the new property Raycaster.layers for selectively ignoring 3D objects during raycasting.

1 Like

I hope it is that, however I should have mentioned that those invisible objects are not actually in the scene, its just raycaster somehow having 2 different height points to walk on of a single object

It does not matter if the objects are part of the scene graph.