问题描述
为了检查碰撞,我正在尝试制作一个球形的光线爆发,但是根据每条光线撞击的内容或位置会发生特定的交互.因此,为什么我使用光线而不是像 OverlapSphere
这样更简单的东西.
我正在寻找如何制作球体的原因是因为我可以对光线使用相同的数学运算,让它们到达球体所在位置的顶点.但是我能找到的每一种制作球体的方法都是让线条更靠近两极,这是有道理的,因为它很容易做到.但正如你可以想象的那样,它对我当前的项目没有那么有用.
TL;DR:如何制作具有等距顶点的球体?如果它不是完美等距也很好,它只需要非常接近.如果发生这种情况,如果您能提供差异有多大以及在哪里(如果适用),那就太好了.
补充说明:我看过
要在 Unity 中调出这样的球体,只需执行以下操作:
如您所知,您可以立即访问顶点
Mesh mesh = GetComponent().mesh;Vector3[] vv = mesh.vertices;int kVerts=vv.Lengthfor (int i=0; i
请注意,您可以轻松检查球体的哪个部分";他们通过(例如)检查他们离你的城市"有多远;(或其他)或仅检查(例如)z 值以查看它们位于哪个半球......等等.
此外...
请注意.关于您想要这样做的总体原因:
<块引用>但是会根据每条光线的照射对象或位置发生特定的交互
请注意,使用 PhysX 做到这一点再简单不过了.(Unity 中完全内置的游戏物理特性.)事实上,我从来没有在不做特定"事情的情况下看到碰撞.取决于它击中的地方!"
例如,您可以通过 http://docs 获取联系人所在的位置.unity3d.com/ScriptReference/RaycastHit-point.html
值得注意的是,在休闲编程中写出接近 PhysX 性能的东西是绝对不可想象的.
我希望这会让事情变得更容易!
I'm trying to make a spherical burst of rays for the purpose of checking collision, but having specific interactions happen based upon what or where each ray hit. Hence why I'm using rays rather then something simpler such as OverlapSphere
.
The reason I'm looking for how to make a sphere is because I can use the same math for my rays, by having them go to the vertices of where the sphere would be. But every way I can find for making a sphere has the lines get closer the near to the poles, which makes sense, as its pretty easy to do. But as you can imagine, its not that useful for my current project.
TL;DR: How do I make a sphere with equidistant vertices? If its not perfectly equidistant its fine, it just needs to pretty close. If this happens, it would be great if you could give how much the difference would be, and where, if applicable.
Extra notes: I've looked at this and this, but the math is way over my head, so what I've been looking for might've just been staring me in the face this whole time.
Are you aware that the sphere given to you by Unity is in fact designed
with this exact goal in mind?
ie, the entire raison d'etre of the sphere built-in to Unity is that the points are fairly smoothly space ...... roughly equidistant, as you phrase it.
To bring up such a sphere in Unity, just do this:
You can then instantly get access to the verts, as you know
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vv = mesh.vertices;
int kVerts=vv.Length
for (int i=0; i<kVerts; ++i)
Debug.Log ... vv[i]
Note you can easily check "which part of the sphere" they are on by (for example) checking how far they are from your "cities" (or whatever) or just check (for example) the z values to see which hemisphere they are in .. et cetera.
Furthermore...
Please note. Regarding your overall reason for wanting to do this:
but having specific interactions happen based upon what or where each ray hit
Note that it could not be easier to do this using PhysX. (The completely built-in game physics in Unity.) Indeed, I have never, ever, looked at a collision without doing something "specific" depending on "where it hit!"
You can for example get the point where the contact was with http://docs.unity3d.com/ScriptReference/RaycastHit-point.html
It's worth noting it is absolutely inconceivable one could write something approaching the performance of PhysX in casual programming.
I hope this makes things easier!
这篇关于制作一个顶点等距的球体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!