2 ms·
Casting a ray into a world with millions of triangles is not terribly cheap. Tracing a parabola through that world is significantly more expensive. Tracing an a
by forrestthewoods 7y ago
Casting a ray into a world with millions of triangles is not terribly cheap. Tracing a parabola through that world is significantly more expensive. Tracing an arbitrary trajectory with simulated drop/drag is even worse.
Game servers often run at a mere 20Hz or 30Hz. Getting to 60 is hard. The question isn’t merely “is it expensive”. It’s “what’s the worst case and how expensive it is to add on top of what we already do”. Is 1 millisecond a lot or a little? (Spoiler: it’s a lot)
Modern CPUs are fast. But single threaded performance hasn’t improved exponentially. You could technically throw cores at the probably. But games want to maximize total server instances. You’re not likely going to throw 8 cores at one instance.
Go download Unity and find a reasonably complex scene. Start calling Physics.Raycast with different locations and directions. See how many calls you can make in 1ms.
- sillysaurusx 7y agoCasting rays into a world with millions of triangles is in fact pretty darn cheap now. Again, I will wager you $10 that you can cast hundreds of rays per tick with zero perceptual loss in performance. If you drop by 1ms for 100 raycasts, the physics engine is broken. I mean this in the nicest way: have you tried it? If you do, you’ll discover you can cast almost as many rays as you want, against almost arbitrarily complex scenes. Whatever the server is using for its physics representation (which you need anyway) is what rays will use. And you’re already simulating some physics at 20Hz. I used 60Hz to point out I was already casting hundreds of rays at 60Hz in 2008. Servers have only gotten better and faster, and the scenes have become exponentially more complex. But if you won’t try it, you won’t try it. I can’t really think of any other way to make the point, short of pulling up a chart showing how many millions of raycasts you can do now against scenes with millions of triangles. The whole point of spatial data structures is that you don’t have to check millions of triangles, even if your scene has millions of triangles. I think unity has caused a lot of harm in the sense that devs have no idea what it’s actually doing. Ray.Cast might as well be black magic. Is it expensive? Who knows? Maybe it takes 16ms per raycast! The worse part is that Ray.Cast also becomes the lens through which devs view the world. If unity’s raycast system is slow, then suddenly “all games everywhere cannot do this thing.” But unity is often slow!
- forrestthewoods 7y agoYeah man. I’ve got some experience dealing with raycasts. Not really interested in getting into a resume fight. We’re a bit off the original point. Which is whether ballistics are computationally complex. I’d say so. Lots of players, lots of guns, complex geometry (static and dynamic). Pretty much everyone has had to deal with optimizing raycasts. Parabolic arcs are even more expensive to intersect. And we’ve not even thrown AI into the mix. I’m not sure I’ve ever seen an AI drop a bullet through a narrow gap across a map. But TBH not many games have ballistics to begin with. Much less ballistics plus AI. I’m sure there’s a few. But it isn’t common.