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.
Does that mean I have to save every single surface wall’s positions into an array or object and compare during every single character transition? In my actual live production link there’s spaces with a lot more rooms and walls than this demo example. So wouldn’t that be really slow to compute in real time?
No just the bounding box or bounding sphere. In this video alot of collision detection is happing.
Video
No ray casting no external lib except for 3JS.
You could also turn the floor to grid, like chess board or maze and move the character from one square to the next.
In all of the examples I read, it seems that the containsPoint() function is used to check whether the bounding box intersects with a point. How can I check if the bounding box collides with any wall if I don’t have every single wall position?
Alternatively, is there anyway to check if the bounding box intersects with wireframes instead?