Question by
xshakurbozz · Mar 08, 2018 at 11:06 AM ·
androidaccelerometer
Accelerometer Input for cube movement (android)
Hello guys,
I'm making a mobile game for android. The accelerometer input is working perfect but the movement doesn't work. On PC it works with WASD. (movement works). But on my smartphone it doesn't work with the movement.
Here is my CubeMovement code:
[SerializeField] private float movementSpeed = 0.0f; private Rigidbody myRB; #endregion
#region UnityFunctions
void Start ()
{
myRB = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
transform.Translate(Input.acceleration.x, 0, 0);
Move();
}
#endregion
private void Move()
{
if(Input.GetAxis("Horizontal") != 0)
{
float hAxis = Input.GetAxis("Horizontal");
Vector3 moveDir = new Vector3(hAxis, 0, 0);
myRB.velocity = moveDir * movementSpeed * Time.fixedDeltaTime;
}
}
I hope someone can help me and sry for my bad english, I'm from Switzerland.
Thanks in advance.
EDIT: with the movement, I mean that the cube rolls
Comment