Having a giant box collider for the door computer prefab wasn’t working out so well. Anytime the player was facing away from the door computer and zoomed into something on the opposite wall, the HUD tooltip for interacting with the door computer was still showing up. This is not what I wanted to have happen. As you can see, the collision box was large enough to grab the player while they were somewhat next to the box–which was fine until I realized that if you are interacting with the power relay right next to the door (or one of several power relays, as their whole point is to be able to be deployed in groups) meant that you would have to then step out of the door computer box.
But I had another problem to solve first: every time I entered a collision box and
OnTriggerEnter() was called,
OnTriggerExit() was being called on other collision geometries associated with my player. Ugh! The fix ended up being very simple. In the end, I needed to enable the “Is Kinematic” flag on the door computer’s rigid body.
With that problem out of the way, I could tackle the issue of the door computer trigger and making my interactions a bit more precise. Here’s what the box looked like:
To solve this problem, I decided to create a sphere collider in front of the player’s head and at the same angle as the camera, attaching it to the camera’s rig. By doing this, anytime I rotate around the player, the sphere will collide with any interactable I am close enough to for an interaction to occur.
The first thing I did was shrink down the collision box to something more practical:
That’s better. Next, I created a “player lookat collider” sphere on the angle and side of the player opposite of the camera:
Having the sphere as a child component of the camera rig made it so that all the orbit calculations I wrote for the camera were automatically applied to the sphere when mouse input is provided. Here’s another screenshot of the collider sphere, together with the body collision spheres:
And here is a demo of the precision collider working. Notice how if I don’t look at the computer, the HUD instructions for the computer don’t show up: