Answer the question
In order to leave comments, you need to log in
unity. How to implement camera rotation that allows for a sudden change in rotation?
You need to be able to rotate the camera with the mouse. Previously it was implemented like this:
void Update()
{
X = Input.GetAxis("Mouse X") * speeds * Time.deltaTime;
Y = -Input.GetAxis("Mouse Y") * speeds * Time.deltaTime;
transform.rotation = Quaternion.Euler(Y, X, 0);
}
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
X = Input.GetAxis("Mouse X") * speeds * Time.deltaTime;
Y = -Input.GetAxis("Mouse Y") * speeds * Time.deltaTime;
transform.rotation *= Quaternion.Euler(Y, X, 0);
if (Input.GetKeyUp(KeyCode.Escape))
{
Cursor.lockState = CursorLockMode.None;
}
}
Answer the question
In order to leave comments, you need to log in
private float X, Y, Z;
public int speeds;
private float eulerX=0, eulerY=0;
// Use this for initialization
void Start () {
Cursor.lockState=CursorLockMode.Locked;
}
// Update is called once per frame
void Update () {
X = Input.GetAxis("Mouse X") * speeds * Time.deltaTime;
Y = -Input.GetAxis("Mouse Y") * speeds * Time.deltaTime;
eulerX = (transform.rotation.eulerAngles.x + Y) % 360;
eulerY = (transform.rotation.eulerAngles.y + X) % 360;
transform.rotation = Quaternion.Euler(eulerX, eulerY, 0);
if (Input.GetKeyUp (KeyCode.Escape)) {
Cursor.lockState = CursorLockMode.None;
}
}
just change the sign "*=" to "="
rotation 721 degrees = 1 degree)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question