Ray picking

It would be great if we could interact with the game objects. In a 2D scene, it is easy as we can map the 2D coordinates of the game object with the input coordinates. However, in a 3D game, it is different as the game object is positioned in 3D world coordinates and the input is available as 2D screen coordinates. A familiar scenario is a first person shooter game, wherein on shooting the bullet it is traced through the scene until a collision is detected. Ray picking is the process of shooting a line or ray from the camera through the 2D view port into the 3D game world until it hits an object, as shown here:

Ray picking

The following code will ...

Get Learning LibGDX Game Development - Second Edition 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.