I’m trying to move my camera (A) in the middle and perpendicular to two objects (at C and D). I can find the midpoint in (B), but I can’t get my mind around the math that is needed to rotate my camera to be facing the mid point (B) too.
Moving it to the middle is no problem, I can use this:
To calculate the location in the middle, you can use Vector mathematics instead of doing it manually:
Vector3 result = sourceObject + (targetObject - sourceObject) / 2;
If you want to move it along the line towards A, simply rotate the vector between D and C left by 90 degrees, then add it to B.
Vector3 midCD = sourceObject + (targetObject - sourceObject) / 2;
Quaternion ninetyLeft = Quaternion.AngleAxis(90, Vector3.up); // to rotate 90 degrees left, rotate 90 degrees around the Y axis
Vector3 towardsA = (ninetyLeft * (targetObject - sourceObject)).normalized; // rotate the vector that points from C to D by 90 degrees left, then you get the vector that points from B to A. Normalize to make it of size 1.
Vector3 result = midCD + towardsA * distanceTowardsA;
Then to put the camera and make it face point B, you can use transform.position and transform.LookAt()`: