Limiting rotations around x and z axis not working
I'm building a tilt labyrinth-style game, where you tilt the entire board and let a ball roll around it through a maze.
I've managed to get the board tilting left/right/forward/backward fine, but I can't get the board to stop rotating past a certain point. Any ideas where I'm going wrong (I'm still kinda new to Unity so I'm probably doing something stupid...)?
using UnityEngine;
using System.Collections;
public class TiltBoard : MonoBehaviour {
public float tiltSpeed = 5.0f;
public float forwardBound = 15.0f;
public float backwardBound = 345.0f;
public float leftBound = 15.0f;
public float rightBound = 345.0f;
void Update(){
//Capture keyboard input
float xRot = Input.GetAxis("Vertical") * tiltSpeed*Time.deltaTime;
float zRot = Input.GetAxis("Horizontal") * tiltSpeed*Time.deltaTime;
//Reset values if board would tilt more than it's allowed
if(transform.eulerAngles.x + xRot > forwardBound && transform.eulerAngles.x + xRot < backwardBound){
//This is never reached - not sure why
xRot = 0.0f;
}
if(transform.eulerAngles.z + zRot > leftBound && transform.eulerAngles.z + zRot < rightBound){
//This is never reached - not sure why
zRot = 0.0f;
}
//Rotate the board
transform.Rotate(xRot,
0.0f,
zRot,
Space.World);
}
}
maybe you want to ask OR not AND. || ins$$anonymous$$d of &&
Your answer
Follow this Question
Related Questions
Euler Angles in code / inspector different (both local & global) 1 Answer
Convert movement direction into rotation? 0 Answers
How to rotate a camera slowly along a tween? 1 Answer
is it possible for velocity vectors to be added on the players axis? 1 Answer
Can you use transform.Translate with pixels instead of units? 0 Answers