Averaging camera positions and rotations

Hi all,
I’m a Level Designer, so I’m great at knowing what I want, and then irritating those with programming experience. Sorry if this is a noob question.

I’ve found (in professional life, where we have programmers on tap) that being able to average multiple ‘cameras’ (or any object with position/rotation), and set the Main Camera to that averaged position/rotation is a really nice, smooth way to get an offset that is dynamic to player movement.

For instance, one might have a straight Follow Cam attached to the player character, but average it with a static camera that points to an object of interest in a room, thereby giving a subtle hint to the player.

It’s also nice and easy to tweak the multiple ‘cameras’ in the editor.

So my question is does anyone know of a simple way to achieve this in java?

Like a script that would simply allow you to select any 2 objects and transfer the average of their position/rotation to the object it’s attached to (Main Camera in this example).

Any input, including telling me I’m missing something totally obvious, much appreciated.

Hi, welcome to the forum!

Averaging positions is just like finding the average of a list of numbers: add them together and divide by the number of positions there are:-

// a, b and c are all Vector3
var average: Vector3 = (a + b + c) / 3.0;

Finding the “average” of Quaternions would not necessarily give you a useful result although you can find the average of the camera’s angles in different axes individually. However, a better approach might be to find the average of a set of target points that the cameras are looking at and use transform.LookAt to point the camera at the resulting point.

Thanks dude, I have a place to start now. And a few words to google!
Ta.