简体   繁体   English

p5.j​​s 中 3d 对象的碰撞检测

[英]Collision detection of 3d objects in p5.js

I am working on a infinite runner game, where 3d objects are involved - A rover and some obstacles, that move on a terrain.我正在开发一个无限跑步游戏,其中涉及 3d 对象 - 漫游者和一些障碍物,它们在地形上移动。 The game is made using p5.js WebGL functionality.该游戏是使用 p5.js WebGL 功能制作的。 I have almost completed the game, but the game should end when the rover hits any obstacle.我几乎完成了游戏,但是当流动站撞到任何障碍物时游戏应该结束。 I just want to know if I can detect the collision of both the 3d objects(the rover is a plane, and the obstacle is custom loaded model) and end the game...Simply, I want to know whether collision detection in WebGL is feasible, and if so how?我只是想知道我是否可以检测到两个 3d 对象的碰撞(流动站是飞机,障碍物是自定义加载的模型)并结束游戏...简单来说,我想知道 WebGL 中的碰撞检测是否是可行,如果可行,怎么办? Please help me out on the same.请帮助我。 Thank you.谢谢你。

Ideally, indeed, you'd post a minimal sketch of your attempt at detecting the collision: something to make it easier for other to contribute (without making to many wild guesses on your behalf).实际上,理想情况下,您会发布您尝试检测碰撞的最小草图:让其他人更容易做出贡献的东西(无需代表您做出许多疯狂的猜测)。

One idea is to check if the bounding box of the 3d model (defined by it's minX, minY, minZ, maxX, maxY, maxZ values) intersects with the plane (or the bounding box of the plane if it's simpler to keep things consistent).一个想法是检查 3d 模型的边界框(由它的 minX、minY、minZ、maxX、maxY、maxZ 值定义)是否与平面相交(或者如果保持一致更简单,则与平面的边界框相交) . It won't be 100% accurate, depending on the loaded model (we don't even know what that is is), but it's a decent initial step.它不会 100% 准确,具体取决于加载的模型(我们甚至不知道那是什么),但这是一个不错的初始步骤。

For more accuracy a convex hull would be handy.为了更准确,凸包会很方便。 If computing that from scratch in p5.js might prove difficult, perhaps you could use the same 3D editor to export the model to also generate a convex hull of the original model and export that to be used as simpler collision mesh.如果在 p5.js 中从头开始计算可能很困难,也许您可​​以使用相同的 3D 编辑器来导出模型以生成原始模型的凸包并将其导出以用作更简单的碰撞网格。

Additionally, even through more advanced, you can look into using a physics engine such as ammo.js to handle the heavy collision math (and more) for you.此外,即使更高级,您也可以考虑使用诸如ammo.js之类的物理引擎来为您处理重碰撞数学(以及更多)。 (checkout the vehicle demo ). (查看车辆演示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM