'Three JS unable to raycast to mesh walls
I’m trying to raycast from the center of a character to detect distance to walls and prevent collisions. I’ve set both the material to DoubleSide as well as updated MatrixWorld but I’m still getting an empty intersect array.
My code is below:
mesh_parent_object.updateMatrixWorld();
mesh_parent_object.material[0].side = THREE.DoubleSide;
var raycaster = new THREE.Raycaster();
var vector_origin = new THREE.Vector3(character.position.x, 0, character.position.z);
var vector_target = new THREE.Vector3(-1.2741646766662598, character.position.y, 1.8035423755645752);
var vector_direction = vector_target.clone().sub(character.position).normalize();
raycaster.set(vector_origin, vector_direction);
var intersects = raycaster.intersectObject(mesh_parent_object, true);
I’ve included a screenshot showing that the raycast intersects the walls and even goes through.
Can someone please help me get the intersect values for meshes like this?
Thank You!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

