- Home /
Weird Rotation Reset
I'm creating a game that requires the player to tilt a table to navigate a ball through a maze. I've gotten the table to rotate around the Z and X axes as I need them to, however whenever I switch which axis the table is rotating around the table resets and rotates from the flat position. Then if I switch axes again the table resets to its most recent rotation around the current axis. Example: Z-rotation --> attempt X-rotation --> table resets --> X-rotation. I apologize if this doesn't make any sense.
public float rotationSpeed = 1;
public float resetSpeed = 10;
private Quaternion level;
private float minX = -30;
private float maxX = 30;
private float minZ = -30;
private float maxZ = 30;
private float rotX;
private float rotZ;
// Use this for initialization
void Start() {
level = transform.rotation;
}
// Update is called once per frame
void Update()
{
rotX += Input.GetAxis("RotateX") * rotationSpeed;
rotX = Mathf.Clamp(rotX, minX, maxX);
rotZ += Input.GetAxis("RotateZ") * rotationSpeed;
rotZ = Mathf.Clamp(rotZ, minZ, maxZ);
if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
{
transform.rotation = Quaternion.AngleAxis(rotX, Vector3.right);
rotX = Mathf.Clamp(rotX, minX, maxX);
}
if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
{
transform.rotation = Quaternion.AngleAxis(rotZ, Vector3.forward);
rotZ = Mathf.Clamp(rotZ, minZ, maxZ);
}
Your answer
Follow this Question
Related Questions
how to make a detect rotation script for negative rotation too 2 Answers
When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers
How do I rotate an object when I press down a key and then it rotates back when I release the key 0 Answers
how to rotate a gameobject in a given direction and stop when it's done 1 Answer
Translate speed keeps changing 1 Answer