- Home /
Moving the camera with fixed angle on x and z-axis
The problem is that a camera with a z-axis rotation moves to the "ground" when moving the z-axis. Is there any way to prevent the moving to the ground?
Something like calculate the the distance it makes towards the ground via Pythagorean theorem and giving that value to the y-axis(probably the solution but i don't know how to do it).
Thanks.
not quite clear HOW you are moving the camera, which I suspect will be critical. It sounds like the ground is on your Y axis, so I'm not clear why changing the Z position of the camera would move it vertically at all.
I have a normal terrain on x/z-axis and i want to move the camera in x/z-axis with an angle i defined, i don't want to move the y -axis at all.
So are you wanting the camera to orbit and move around the plane?
If so, there's a few ways of doing it very easily.
Answer by Dragonisser · Dec 20, 2016 at 05:42 PM
Here is the code @glurth
Something ive found online and the z-axis moving with the rotation of the camera is why it moves towards the ground.
void Update() {
float xAxisValue = Input.GetAxis("Horizontal");
float zAxisValue = Input.GetAxis("Vertical");
if (Camera.main != null)
{
Camera.main.transform.Translate(new Vector3(xAxisValue, 0.0f, zAxisValue));
}
}