Ray and object casting
Another common feature of physics engines is the ability to cast a ray from one point to another and generate collision information with one or more of the objects in its path. This is known as raycasting. It is pretty common to implement several gameplay mechanics through raycasting, such as firing a gun. This is typically implemented by performing raycasts from the player to the target location and finding any viable targets in its path (even if it's just a wall).
We can also obtain a list of targets within a finite distance of a fixed point in space using a Physics.OverlapSphere() check. This is typically used to implement area-of-effect gameplay features, such as grenade or fireball explosions. We can even cast ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access