Hi all,
I was rotating the camera to an object using something like this:
Quaternion targetRotation = Quaternion.LookRotation(targetPosition - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationDamping * Time.deltaTime);
Worked fine but then I adjusted the lens shift in the physical camera properties and it no longer points at my object. Does anyone know the formula to rotate a camera transform so that the view frustum of the camera is pointing at a target?
Thanks
Not sure what you mean by “lens shift.” If it is a simple offset, you might be able to create a ghost offset object in the hierarchy of what you are trying to look at and just look at that instead, as long as it is offset identically in space to your lens.
The Lens Shift I am referring to is in the Physical Camera settings and is being used to reduce perspective distortion.
I am not 100% sure but that sounds like it makes an oblique frustum. That means that the +Z central axis of the camera regard is not in the center of the picture. However, that is the thing that LookAt will look at.
What you need to do is identify (and this is where googling oblique frustum will be useful) how to study your “shift” effects ( probably by using the camera’s matrix values) and calculate the angular difference between the center of the screen, and the +Z of the oblique frustum.
With that information, you can point any other transform at the desired look point, then offset your camera by that angle, and it will make it go forward the way you want.
But remember, I think if you’re trying to do this on an oblique frustum, likely as you look towards and MOVE towards, your path will actually describe a curve, not a straight line, because as you move, the fixed angular offset from “Look” to “move” will remain the same while the distance to the object will change. It’s hard to explain without drawing, but hey, give it a try, make us all proud of you!
Thanks - I’ll give it a try but I fear the maths might be beyond me. However, I don’t want to disappoint you so will I will give it my best! 
1 Like