- Home /
Question by
gonzalitosk8 · Mar 17, 2015 at 09:15 PM ·
camerarotationcareffecthorizontal
rotate the camera in the z axis
Hi, I'm looking for a little help. as I can rotate the camera in the z axis by pressing the "horizontal" button? eg:
to turn right, the z axis rotate from 0 ° to 25 ° to turn left, the z axis rotate from 0 ° to -25
Comment
Answer by giulio-pierucci · Mar 17, 2015 at 11:16 PM
It can be written better, sure.
using UnityEngine;
using System.Collections;
public class RotateZ : MonoBehaviour {
public float speed = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float s = Mathf.Sign(Vector3.Cross(transform.up, Vector3.up).z);
float angle = Vector3.Angle(transform.up, Vector3.up);
float ammount = Input.GetAxis("Horizontal") * Time.deltaTime * -speed;
if(angle < 25 || s == Mathf.Sign(ammount)) transform.Rotate(0, 0, ammount);
}
}
Your answer
Follow this Question
Related Questions
how to operate 2 cameras simultaneously 1 Answer
Want to rotate camera horizontally around object using left and right arrow keys 0 Answers
Camera is constantly locked on the Y-Axis 1 Answer
Camera position/rotation reset after 5 seconds of mouse inactivity 0 Answers
Rotation of a camera viewport 0 Answers