Hi friends!!
I am finalizing details of my first game for Android and I had some doubts.
I am making a game in which the movement is with the accelerometer. The inconvenience is that when I’m on the bus or if the device vibrates (a message arrives), this interferes with the player’s movement. It moves crazy everywhere, and the gaming experience becomes very bad. I need to soften this movement a bit to improve that experience. Any suggestions?
THANKS A LOT!
My script movement.
public class MovimientoPersonaje : MonoBehaviour {
[SerializeField]
public float speed = 10f;
public SpriteRenderer spriteRotar;
public Rigidbody2D boxDudeRigid;
public float variablePosicion = 0f;
MatrixCalibrate calibration;
public void MovimientoAcelerometro () {
Vector3 dir = Vector3.zero;
dir.x = (Mathf.Abs (_InputDir.x) > 0.07f) ? _InputDir.x : 0;
if(dir.sqrMagnitude > 1)
dir.Normalize();
dir*= Time.deltaTime;
transform.Translate(dir * speed);
if(_InputDir.x < -0.02){
spriteRotar.flipX = true;
}
if(_InputDir.x > 0.02){
spriteRotar.flipX = false;
}
}
//Method for calibration
//Method to get the calibrated input
Vector3 getAccelerometer(Vector3 accelerator){
Vector3 accel = this.calibration.calibrationMatrix.MultiplyVector(accelerator);
return accel;
}
//Finally how you get the accelerometer input
Vector3 _InputDir;
// Use this for initialization
void Start () {
calibration = GameObject.Find ("Calibrate").GetComponent<MatrixCalibrate> ();
}
// Update is called once per frame
void Update () {
_InputDir = getAccelerometer(Input.acceleration);
//then in your code you use _InputDir instead of Input.acceleration for example
//transform.Translate (_InputDir.x, 0, -_InputDir.z);
MovimientoAcelerometro ();
}
}