I have a camera that I’m using to see interactable items, so its far clip plane and FOV are smaller than the actual camera used to see the world. I’m trying to figure out how to find which interactable item is the most centered in the camera view, because sometimes there will be multiple interactable items in camera view at the same time, and I only want the most centered item to activate when the interact key is pressed. Does anyone know how to do this?
You can use Vector3.Dot. Use a loop to iterate through all the interactable objects and the object with the highest dot product in relation to the camera’s transform.forward is the one closest to the center of the camera.
Vector3 dot=Vector3.Dot(cam.transform.forward,(object.transform.position-cam.transform.position).normalized);
1 Like
How do I find the dot product?