Accelerometer issue

Hi All,
I got an issue with the accelerometer, m developing a game and used the character animation script from unity and modified it to work on accelerometer but i want the accelerometer to take the device orientation whether it is parallel to ground or perpendicular and then it should take the adjust the accelerometer accordingly.
currently in my demo i have to tilt it forward very much to make my character fast, but my main concern is the accelerometer accd to orientation.
i have attached my script, ne suggestions in the code will be appreciated.

thank u all

var speed = 3.0;
var rotationSpeed = 200.0;
private var curSpeed = 0.0;
var followMe : GameObject;

function Awake(){
	iPhoneSettings.verticalOrientation = false; 	 
}

function Update () {
	
	// Rotate around y-axis
	var newRotation = -iPhoneInput.acceleration.y*rotationSpeed;
	transform.Rotate(0, newRotation * Time.deltaTime, 0);
	// Calculate speed

	var newSpeed = iPhoneInput.acceleration.x*speed;
		// Move the controller
	var controller : CharacterController = GetComponent (CharacterController);
	var forward = transform.TransformDirection(Vector3.forward);
	controller.SimpleMove(forward * newSpeed);
	
	// Update the speed in the Animation script
	SendMessage("SetCurrentSpeed", newSpeed, SendMessageOptions.DontRequireReceiver);
	SendMessage("SetCurrentLean", iPhoneInput.acceleration.y , SendMessageOptions.DontRequireReceiver);
}

the newspeed is passed to a the complex walk blend script of character animation

Keep in mind that the accelerometer is always active and the only time it will have a zero value would be if you were in space (even sitting on your desk it shows the result of Earth’s gravity). So it’s up to you to choose, or even better to allow your end user to choose, the “zero” point. Some folks might want to play your game while their device is parallel to the floor (screen pointing up), others while it’s perpendicular to the floor (screen facing them). You choose, or let them choose what is “zero” then save that in a variable and simply subtract it from the current value and there you go.

Did I understand your question right? If not then let me know and we’ll keep at it. If I did then give that a try and post up if you have any follow-up questions.

Two other tips:

  1. Post iPhone-specific questions like this in the iPhone Development section in the future as you’re more likely to get prompt replies there. I’ll move this post for you. :slight_smile:

  2. When including code in your posts use the Code button or manually wrap it in code-blocks for better formatting. I’ll edit your post so you can look at that as an example.

Hey thanks dude i will give it a try and post my comments as soon as i get it working, n i ll make sure i post my code under the proper section.