三个 JS 无法光线投射到网格墙
我正在尝试从角色中心进行光线投射,以检测到墙壁的距离并防止碰撞。我已将材质设置为 DoubleSide 以及更新的 MatrixWorld,但我仍然得到一个空的相交数组。
我的代码如下:
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’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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论