0
votes

The following code allows me to rotate my object via accelerometer.

void launch() {
    x = Input.acceleration.x;
    finalSpeed = liftSpeed - velocity;
    GetComponent<ConstantForce2D> ().relativeForce = Vector3.right * (finalSpeed);
    rotationZ += x * sensitivityZ;
    rotationZ = Mathf.Clamp (rotationZ, 45, 135);
    transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, rotationZ);
}

The code example I pulled this from had:

transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, -rotationZ);

This caused my object to be upside down so I changed it from -rotationZ to rotationZ:

transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, rotationZ);

The object rotates back and forth in the desired angular limits but it rotates the wrong way when I tilt. How can I reverse it? IE I tilt my phone left my object goes right. I want to tilt left and go left. Vice versa for right.

1

1 Answers

0
votes

GOT IT. I simply changed

    rotationZ += x * sensitivityZ;

TO:

    rotationZ -= x * sensitivityZ;

Now it is rotating in the correct direction