Does anyone have an idea of how to offset the center point of the accelerometer input?
For instance, I would like to have a slightly tilted up phone be the neutral position, so that in using the accelerometer input for movement, the screen can be more visible over all and less tipped away from the user.
the accelerometer has no position so you can not offset it.
it only gives acceleration into 3 dimensions, which is independent of the position.
it does not give any rotation or alike, which would be position dependant
what you are potentially asking for is calibrating its “0 direction”
To answer what you are trying to do, you just don’t assume zero in the z. Set 0 z to be positive (say .2), or negative if you want them lying down Use that value to adjust the z value received from iPhoneInput, along with partial adjustments to x and y to readjust them to the new value of z and you’re there. You can also make it user settable, though I would give them a warning when they start going past .4 or .5 because they will lose fidelity of the x and y as they tilt further. You can do this without the adjustment of x and y, but it will turn out to be less adjustment for the same movement.
Hello,
well what i try to do is implement a Calibration Menu like you found in some iPhone Games (Labyrinth etc)…
The Problem i have is that i can not store the new Value so that i can read it later in the Game…
I don’t know if there is a easy Calibration Solution for the iPhone…but in the Meantime maybe this is usefull too
Here is what i use @ the moment:
!Artist Code!
using UnityEngine;
using System.Collections;
public class FlightScript : FlightScrip2 {
public float accel = 0;
public float smooth = 5; //Steer smoothing Value
float lastZ = float.PositiveInfinity;
iPhoneOrientation lastKnownOrientation;
void FixedUpdate () {
float steer = 0;
if ((checkForActive == null) || checkForActive.active) {
float z = Mathf.Clamp(-2f * iPhoneInput.acceleration.y, -1f, 1f);
if (smooth > 0 lastZ != float.PositiveInfinity)
z = Mathf.Lerp(lastZ, z, smooth * Time.deltaTime);
lastZ = z;
steer = z;
accel = Mathf.Clamp(4f * (-iPhoneInput.acceleration.z -0.5f), -1f, 0f);
for (int i = 0; i < iPhoneInput.touchCount; i++) {
iPhoneTouch touch = iPhoneInput.GetTouch(i);
if ((touch.phase != iPhoneTouchPhase.Ended) (touch.phase != iPhoneTouchPhase.Ended)) {
accel = 1.0f;
}
}
}
So Steering is smooth out with the Value 5. Acceleration Forward is done by touching the Screen and Accel Backward is done by moving the iPhone to you…
But well these mix from C#, Unity JavaScript and Boo is too much i think… it makes it all more complicated…