Search Unity

Accelerometer filtering example in Unity docs. A typo?

Discussion in 'iOS and tvOS' started by jocoUnity, Feb 3, 2012.

  1. jocoUnity

    jocoUnity

    Joined:
    Oct 2, 2011
    Posts:
    25
    Tried to implement this filtering for accelerometer input as recommended by Unity Docs but I get an error that the parameters in Mathf.Lerp aren't floats. Looking at it of course they aren't all floats.

    Is this a typo in the docs?


    Code (csharp):
    1. var AccelerometerUpdateInterval : float = 1.0 / 60.0;
    2. var LowPassKernelWidthInSeconds : float = 1.0;
    3.  
    4. private var LowPassFilterFactor : float = AccelerometerUpdateInterval / LowPassKernelWidthInSeconds; // tweakable
    5. private var lowPassValue : Vector3 = Vector3.zero;
    6. function Start () {
    7.     lowPassValue = Input.acceleration;
    8. }
    9.  
    10. function LowPassFilterAccelerometer() : Vector3 {
    11.     lowPassValue = Mathf.Lerp(lowPassValue, Input.acceleration, LowPassFilterFactor);
    12.     return lowPassValue;
    13. }
     
  2. jocoUnity

    jocoUnity

    Joined:
    Oct 2, 2011
    Posts:
    25
    Doh! Sorry for the clutter ...

    It's suppose to be Vector3.Lerp not Mathf.Lerp