void Update () {
Debug.DrawRay (transform.parent.position,transform.parent.forward*Mathf.Infinity);
}
I have this code, and the ray does not display in the editor. However, when I use the code below, the ray displays. Why is this and how can it be fixed
void Update () {
Debug.DrawRay (transform.parent.position,transform.parent.forward*1000000);
}
Note that the transform.parent is referring to the camera here.
Hello there!
Well, the problem is quite simple, you are trying to tell the editor to draw an infinite line… now don’t get me wrong, it might sound simple to you, but ask yourself this: Can you draw infinite lines? No.
The only thing you can do is raycasting with Mathf.Infinity, and that works because the editor is not drawing something infinite but really just checking any object in that direction if it would be hit by that ray (so basically it’s not infinite, it just checks every single object)
But drawing an infinite line is not something you can really do… If you’re still uncertain, here’s a little example: Say you want to draw an infinite line, and the Editor needs 1ms per 1,000,000 units, now, you want to draw INFINITE units… I don’t know if you’ve been listening to your mathematics teacher, but if you multiply 1ms with infinity, it ends up taking infinitely long to calculate/render it. So basically it’s not impossible, it just takes forever (literally), But I guess the Editor is smart enough to NOT try those kind of things. So I suggest you just put in a really big number if you really need that (10^30 or something) and it’ll end up looking like infinity.
Hope this helped
~Cerbi