# Doppler effect/relative velocity with Cinemachine camera does weird things?

**URL:** <https://qa.fmod.com/t/doppler-effect-relative-velocity-with-cinemachine-camera-does-weird-things/21309>\
**Category:** Unity\
**Created:** [February 29, 2024, 11:41pm UTC](https://qa.fmod.com/t/doppler-effect-relative-velocity-with-cinemachine-camera-does-weird-things/21309 "2024-02-29T23:41:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [March 4, 2024, 10:10pm UTC](https://qa.fmod.com/t/doppler-effect-relative-velocity-with-cinemachine-camera-does-weird-things/21309/4 "2024-03-04T22:10:14Z")

</div>

Hi,

With these changes, all listeners will have Doppler enabled:

Change the `SetListenerLocation` in `RunTimeManger.cs`:

```auto
public static void SetListenerLocation(int listenerIndex, GameObject gameObject, GameObject attenuationObject = null, Vector3 velocity = new Vector3())
{
    if (attenuationObject)
    {
        Instance.studioSystem.setListenerAttributes(listenerIndex, RuntimeUtils.To3DAttributes(gameObject.transform), RuntimeUtils.ToFMODVector(attenuationObject.transform.position));
    }
    else
    {
        Instance.studioSystem.setListenerAttributes(listenerIndex, RuntimeUtils.To3DAttributes(gameObject.transform, velocity));
    }
}

```

Then add

```auto
private Vector3 lastFramePosition = Vector3.zero;

```

to `StudioListner.cs` and replace lines `99 - 137` in with:

```auto
private void Update()
{
    var position = transform.position;
    var velocity = Vector3.zero;

    if (Time.deltaTime != 0)
    {
        velocity = (position - lastFramePosition) / Time.deltaTime;
        velocity = Vector3.ClampMagnitude(velocity, 20.0f);
    }

    lastFramePosition = position;

    if (ListenerNumber >= 0 && ListenerNumber < FMOD.CONSTANTS.MAX_LISTENERS)
    {
        SetListenerLocation(velocity);
    }
}

private void SetListenerLocation(Vector3 velocity)
{
#if UNITY_PHYSICS_EXIST
    if (rigidBody)
    {
        RuntimeManager.SetListenerLocation(ListenerNumber, gameObject, rigidBody, attenuationObject);
    }
    else
#endif
#if UNITY_PHYSICS2D_EXIST
    if (rigidBody2D)
    {
        RuntimeManager.SetListenerLocation(ListenerNumber, gameObject, rigidBody2D, attenuationObject);
    }
    else
#endif
    {
        RuntimeManager.SetListenerLocation(ListenerNumber, gameObject, attenuationObject, velocity);
    }
}

```

Please note this is just a workaround and once there is an update with a fix I will post it here.

---

_[View the full topic](https://qa.fmod.com/t/doppler-effect-relative-velocity-with-cinemachine-camera-does-weird-things/21309)._
