Hi!
A week ago I started my first Unity project ever and I’m really excited to get into it! However, I already have a simple problem which I can’t find an answer to.
The project is an adaptation of a board game to PC. The main screen is an angled shot of the board where the magic will happen. Right now this is my code for camera movement:
public class MainCameraMove : MonoBehaviour {
public float verticalSpeed;
public float horizontalSpeed;
public float maxZ;
public float minZ;
public float maxX;
public float minX;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float v = verticalSpeed * Input.GetAxis("Vertical");
float h = horizontalSpeed * Input.GetAxis ("Horizontal");
transform.Translate (h, 0, v, Space.World);
}
}
I want to insert boundaries so that I am sure that you always see the board. However due to the fact that I use Translate (h,0,v,Space.World) - because the camera is angled - the answer to the question found in tutorials doesn’t work as expected. How can I set boundaries to the camera which is translated according to the world axes? When I went with the simplest
if (h >= maxZ)
h = maxZ;
if (h <= minZ)
h = minZ
The camera went crazy.