Raycast sphere

In order to solve collisions against constraints, we will need to determine some extra information about rays being cast into the world. In our current implementation, each raycast returns a floating point t-value. From this value we can infer if the ray hit anything and if it did at what point the intersection happened. We still need this t-value, but we also need to know the normal of the surface that the ray hit.

Getting ready

In this section, we will start modifying the Raycast function to return more data. To achieve this, we first declare a new RaycastResult data structure. We will also implement a helper method to reset the new RaycastResult data structure.

How to do it…

Follow these steps to update the RaycastSphere function ...

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.