Comments and answers for "Problem rotating camera on negative z axis"
http://answers.unity.com/questions/1617101/problem-rotating-camera-on-negative-z-axis.html
The latest comments and answers for the question "Problem rotating camera on negative z axis"Comment by dan_wipf on dan_wipf's comment
http://answers.unity.com/comments/1617224/view.html
you’re welcone, i’d always use quaternion.euler as a setter method, it get’s you the desired results in most casesFri, 29 Mar 2019 13:24:56 GMTdan_wipfComment by johnny2014 on johnny2014's answer
http://answers.unity.com/comments/1617137/view.html
Amazing, thank you so much. It's good to see i was pretty close though.
have a great day!Fri, 29 Mar 2019 07:22:42 GMTjohnny2014Answer by dan_wipf
http://answers.unity.com/answers/1617122/view.html
Don't use ***transform.eulerAngles*** to set a Value, just use it to Read. Use ***transform.rotation = Quaternion.Euler*** => it's the safest way to get the desired result.
<br>
your code fails due to that you set transform.eulerAngles.z to a float out of 0 - 360. transform.eulerAngles set method only works in the range between 0 and 360.
<br>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRotationExample : MonoBehaviour
{
public float rotationSpeed = 30;
float z;
void Update()
{
z += Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime;
z = Mathf.Clamp(z,-30,30);
transform.rotation = Quaternion.Euler(transform.eulerAngles.x,transform.eulerAngles.y,z);
}
}Fri, 29 Mar 2019 06:06:40 GMTdan_wipf