The code you posted never modifies the camera’s y position, so something else must be going on. Do you have any other code anywhere that may be translating the camera in Y? Are there any collider- or rigidbody- type components on the camera game object? You said, “until it hits the border.” What border? You need to post more information for anyone to diagnose the problem.
You’re right. there is no actual code that modifies the Y axis. That’s why I don t know how to fix the problem.
The following code:
var x = Input.GetAxis("Horizontal") * Time.deltaTime * camspeed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * camspeed;
transform.Translate(x, 0, z);
is attached to the main camera. So if u use WASD you can move the camera around.
The following code:
var minPositionx : float = -5.6; // left border
var maxPositionx : float = 3.4; // right border
var minPositionz : float = -6.5; // left border
var maxPositionz : float = 2.5; // right border
var minPositiony : float = 0; // down
var maxPositiony : float = 10.0; // up
transform.position.x = Mathf.Clamp(transform.position.x, minPositionx, maxPositionx);
transform.position.z = Mathf.Clamp(transform.position.z, minPositionz, maxPositionz);
transform.position.y = Mathf.Clamp(transform.position.y, minPositiony, maxPositiony);
creates a border so that the camera doesn’t move past this point. The problem is, if you reach the border with the camera and still hit like backwars the camera goes up the y axis instead of stopping.
Assuming that the camera’s y-position starts between minPositiony and maxPositiony, there’s still nothing there that would cause it to move in y. Either you have more code you haven’t posted yet that’s causing the problem, or there’s something else going on as I said before.