I want to move an object with acceleration input in unity:
if (...)
transform.translate(vector2.right*speed);
else if (...)
transform.translate(vector2.left*speed);
I don't know what the conditions should be
I want to move an object with acceleration input in unity:
if (...)
transform.translate(vector2.right*speed);
else if (...)
transform.translate(vector2.left*speed);
I don't know what the conditions should be
Well, you can technically achieve this movement without using conditions at all. Simply put something like this in either Update() or FixedUpdate() (FixedUpdate() is recommended).
Vector2 dir = Vector2.zero;
void FixedUpdate()
{
dir.x = Input.acceleration.x;
transform.translate(dir * speed * Time.deltaTime);
}
This is because when your phone is placed flat on a surface Input.acceleration.x is 0. If it is tilted to the right, the value will be positive. If tilted to the left, the value will be negative. Thus leaving you free of conditionals.