image/svg+xml

Vision Selection

Jun 15, 2020

When developing Iron and Steel, a surprisingly difficult problem was determining what the player is selecting.

Initially, the code checked if an object was within a cone (pointed from the camera). This worked for single objects, but failed to behave correctly if multiple objects were in this cone.

The obvious choice to choose the object closest to the player (or camera). We initially found the closest point on an object to the camera and then calculated the angle from where the camera was pointing, but that caused problems like this:

diagram of why selection must not use the closest point
diagram of why selection must not use the closest point

The closest point is not in the selection area even though the object is.

Eventually, we used a custom collision trace in a cylinder in front of the player. This gives us collision points, which are much better for calculating the smallest angle.