VelocityEstimator.GetAccelerationEstimate C# (CSharp) Method

GetAccelerationEstimate() public method

public GetAccelerationEstimate ( ) : Vector3
return Vector3
	public Vector3 GetAccelerationEstimate()
	{
		Vector3 average = Vector3.zero;
		for ( int i = 2 + sampleCount - velocitySamples.Length; i < sampleCount; i++ )
		{
			if ( i < 2 )
				continue;

			int first = i - 2;
			int second = i - 1;

			Vector3 v1 = velocitySamples[first % velocitySamples.Length];
			Vector3 v2 = velocitySamples[second % velocitySamples.Length];
			average += v2 - v1;
		}
		average *= ( 1.0f / Time.deltaTime );
		return average;
	}

Usage Example

    private bool checkIfHit()
    {
        float vel = velocityEstimator.GetAccelerationEstimate().magnitude;

        if (vel > trackGlitchLowerLimit)
        {
            vel = 0;
        }

        //Debug.Log(maxVelocity + " " + vel);
        maxVelocity = Mathf.Max(maxVelocity, vel);

        if (vel > realHitLowerLimit)
        {
            Debug.Log("hit " + vel);
            return(true);
        }
        return(false);
    }