   ## Camera Distance Patch The Camera Distance patch takes an object as an input and outputs the distance between the object’s position along the X, Y and Z axis and the camera. Use this patch to build a world effect enabling users to easily interact with objects in the scene.

### Input

NameDescription

Object

The scene object you want to use.

### Output

NameDescription

Distance

The distance between the camera and the object in meters.

### Example

In the example below, the Camera Distance patch is used in an effect containing audio and screen interactions to control position of the object. The volume of the speaker playing audio increases from 0 to 1 as the user drags the blue object towards the camera and vice versa. To build a graph that causes the volume to decrease as the object’s camera distance increases, we connected:

1. The patch representing the blue Object to the input of the Camera Distance patch.
2. The Camera Distance output to the First Value input of the Multiply patch. We changed the Second Value to -1.
3. The Multiply output to the First Value input of an Add patch. We changed the Second Value to 2.
4. The Add output to the first input of the Clamp patch. We set the Min and Max values to 0 and 1.
5. The Clamp output to the input of a patch representing Speaker0. If we directly mapped the Camera Distance to the Volume without adding the intermediary patches, the volume would increase as the distance increases.

Instead we simulate a real-world scenario where the volume decreases as the object moves away from the camera, using the following patches:

• The Multiply patch first inverses the camera distance by multiplying it by -1. For example, when the camera distance is 1 meter, the volume is -1 (1 x -1).
• The Add patch then adds 2 to the multiplied value so the volume is positive and audible when the object is 1 meter away. For example, when the camera distance is 1 meter, the volume is 1 (-1 plus 2).
• Finally, the Clamp patch keeps the volume between the expected range of 0 and 1 regardless of the camera distance. For example, when the distance from the camera is less than 1 meter, the volume will not exceed 1.