三个 JS 无法光线投射到网格墙

发布于 2025-01-12 05:31:13 字数 987 浏览 4 评论 0原文

我正在尝试从角色中心进行光线投射,以检测到墙壁的距离并防止碰撞。我已将材质设置为 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.

enter image description here

Can someone please help me get the intersect values for meshes like this?

Thank You!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文