move gameObject on z dependently on iOS device movement on x axis...

move gameObject on z dependently on iOS device movement on x axis…

ive got some results, but they are not working how i want them to if im moving device on x axis, but if im rotating its working, but the problem is that i want it to work without rotating

Could someone help me out?

Code:

#pragma strict
    
    var speed = 2;
    var toolScr:_ButtonOldCheck;
    static var canMoveForward:boolean=true;
    static var canMoveBackward:boolean=true;
    var moveTreshold: float=0.1;
    private var xAcc: float=0.0;
    
    function Start()
    {
    	canMoveForward=true;
    	canMoveBackward=true;	
    }
    
    function Update () 
    {
    	var currTool:String=toolScr.oldObj.name;
    	var dir : Vector3 = Vector3.zero;
    	
    	if(currTool=="tool1")
    	{
    		xAcc=Input.acceleration.x;
    		print("reading "+xAcc);
    		
    		if(canMoveForward&&canMoveBackward) MoveObject();
    
    		if(!canMoveForward &&xAcc<0&&Mathf.Abs(xAcc)>moveTreshold) MoveObject();
    		
    		if(!canMoveBackward&&xAcc>0&&Mathf.Abs(xAcc)>moveTreshold) MoveObject();
    
    	}	
    }
    
    function MoveObject()
    {
    	var dir : Vector3 = Vector3.zero;
    	
    	dir.z = Input.acceleration.x;
    
    	if (dir.sqrMagnitude > 1)
    		dir.Normalize();
    
    	dir *= Time.deltaTime;
    	
    	transform.Translate (dir * speed);	
    }

Have you tried manually constraining? either with code or if its a rigidbody - use the constraints checkboxes on the component itself?