Hello Unity Community, I have some problems.
Im using accelerometer for moving my 2d sprite and the problem comes when i want to rotate my 2d sprite according to the device’s accelerometer direction.
Now my code is rotating my character but not on the z axes, only on y and x
Do you know how can i do it to rotate only on z axes and to be facing to the direction
This is my code:
void Update ()
{
Vector3 move = Vector3.zero ;
move.x= Input.acceleration.x;
move.z = Input.acceleration.y;
transform.Translate(Vector3.right * (move.x * maxSpeed) * Time.deltaTime,Space.World);
transform.Translate(Vector3.up * (move.z * maxSpeed) * Time.deltaTime);
if (move != Vector3.zero)
{
transform.rotation = Quaternion.LookRotation(-move);
}
}
Any help will be appreciated !