# Controlling Accelerometer sensitivity

Hi,

I have a script that controls my camera’s y rotation and also locks how far it can rotate on each side. However I have no way of controlling the sensitivity of the accelerometer and how much tilt the phone needs before it starts to rotate. Is there a simple way to control this? Any tips would be highly appreciated!

Here is my script:
#pragma strict

``````var yMinLimit = -180;
var yMaxLimit = 180;

function Start() {

}

function Update () {
var tiltSides = Input.acceleration.x;
tiltSides = Mathf.Clamp(tiltSides, yMinLimit, yMaxLimit);
transform.Rotate(Vector3.up * tiltSides * 1.5);
transform.eulerAngles.y = Mathf.Clamp(transform.eulerAngles.y, 170.0, 211.0);

}
``````

Sure, MrWhyte. I had to get this done by a freelancer, but he came up with a smooth solution for my use in The Sculptor. Heres the script he wrote:

``````#pragma strict

// camera rotation limits
var maxTargetAngle :float = 90;
// tilt limit between 0 and 1
var maxTiltDeviceAngle : float = 0.9;
// output curve
var falloffAngle : float = 3;
// input smoothing, higher = faster
var lerpSpeed : float = 3;
private var outputLerp : float;
// dead zone between 0 and 1
var deadzone : float = 0.1;

//debug
//var inputX : float;

function Start(){
// if using unity4
#if UNITY_4_1
Input.compensateSensors = true;
#endif
}

function Update () {
// debug
//var inputTiltAngle = Mathf.Clamp(inputX, -maxTiltDeviceAngle, maxTiltDeviceAngle); // clamp values to max

// if not using unity 4
// change Input.acceleration.normalized.x to Input.acceleration.normalized.y if using landscape
var inputTiltAngle = Mathf.Clamp(Input.acceleration.normalized.x, -maxTiltDeviceAngle, maxTiltDeviceAngle); // clamp values to max

var outputAngle = Mathf.Pow(Mathf.Clamp(Mathf.Abs(inputTiltAngle)-deadzone, 0, maxTiltDeviceAngle)/(maxTiltDeviceAngle-deadzone), falloffAngle) * maxTiltDeviceAngle;

var outputDevice = Mathf.Clamp(maxTiltDeviceAngle/inputTiltAngle, -1, 1) * outputAngle;

outputLerp = Mathf.Lerp(outputLerp, outputDevice, lerpSpeed * Time.deltaTime); // lerpSpeed variable is defined as 2.5 in my version but can be any value you feel is best
var output = (outputLerp/maxTiltDeviceAngle) * maxTargetAngle; // retarget it to new angle

transform.eulerAngles.y = output;
}
``````