Hi, I’ve just started Unity and have a question about the z axis rotation. In my 3D game, the player/camera is grounded and can only rotate on the x and y axis 360 degrees. If the player presses both up and right arrows though, I found the z axis was activated, so I coded a conditional statement to stop this. I realised that this stopped a diagonal movement occurring. So, I was wondering what would be a good way to allow the player to move in a diagonal motion while keeping the x axis perspective horizontal (instead of looking tilted)?
Thanks.
#pragma strict
// Camera Control
// Momement of the camera (first person)...
var xCameraRotationSpeed : float = 100;
var yCameraRotationSpeed : float = 75;
function Update () {
var h : float = Input.GetAxis("Horizontal") * Time.deltaTime * xCameraRotationSpeed;
var v : float = Input.GetAxis("Vertical") * Time.deltaTime * yCameraRotationSpeed;
if(h){
// If h is true, don't call y axis rotation.
// Stops z axis rotation as a result of x and y axis pressed simutanisouly.
transform.Rotate(0, h , 0);
}
else if(v) {
// Only called if h is false
transform.Rotate(v, 0 , 0);
}
}