For my university project, I am looking to implement collision similar to what is shown in this example. However, I am facing an issue where collision is only working on the top of the object. I referred to this for guidance. My goal is to add collision to the sides of the object cube. How can I achieve this? Which parameter should I modify for this purpose? I attempted to make changes as follows:
raycaster.ray.origin.y -= 10;
raycaster.ray.origin.x -= 0;
However, I observed that this adjustment affects the upper collision position. I have a possible solution in mind, but I lack an understanding of its functionality. Here is the code snippet:
raycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 0, -1, 0 ), 0, 10 );
UPDATE
Following Ivan's suggestion, I have managed to prevent the player from passing through boxes. However, a new problem arises when I approach a box too closely - I get stuck and cannot move at all, even if the box is not visible to the camera. This results in the velocity on the x or z axis becoming zero. How can I resolve this issue?
UPDATED CODE: