ELI5: what is a raycast and what do games use it for?
I keep hearing "just raycast it" in tutorials. As I understand it, a raycast shoots an invisible line from a point in a direction and tells you what it hits first, and how far away it is.
Uses I've seen: checking if a character is on the ground, hitscan weapons, line-of-sight checks for enemies, and figuring out what the mouse is pointing at.
Is that a fair summary? What's the cleverest use of raycasts you've seen?
Comments · 4
Right, and it's the same idea behind line-of-sight checks for enemy AI, bullet hit detection and mouse picking in 3D. Raycasts are cheap, so you can do plenty per frame.
Hitscan weapons in shooters are basically a raycast. The bullet arrives instantly, instead of simulating a projectile that travels.
Is it the same as ray tracing in graphics? The names sound similar, and I'm not sure if I'm mixing them up.
Related but different. Raycasting is a simple query that returns the first thing a line hits. Ray tracing is a rendering method that follows many light rays to calculate realistic lighting.