- Home /
Problem in EulerAngles Understanding ??,EulerAngles.x is not exceeding -90 to 90 range??
Vector3 v;
void Start ()
{
v = Vector3.zero;
}
void Update ()
{
_xRotation = Mathf.Lerp(_xRotation, 0, _lerpRate);
_yYRotation = Mathf.Lerp(_yYRotation, 0, _lerpRate);
v.x += _yYRotation;
v.y += _xRotation;
v.z += 1 * Time.deltaTime;
transform.eulerAngles = v;
// Above code ***
transform.eulerAngles += new Vector3(0, _xRotation, -_yYRotation);
}
Hello friends, I am a beginner in unity and also please forgive my spelling mistake or grammatical mistake in the question.
Actually i am trying to orbit the camera around the player and i have problem in understanding in eulerAngles because when i use code above comment line the camera rotate in 360 angle but when i use code below the comment line the camera rotates only in 180 degree for x axis and for y axis it rotate 360 angle same value same code for x and y value but still this weird behavior. i am guessing this happen because " vector3 v" Declared ones in code above comment line and and in code below comment line every time it register new vector3 m i correct?? please explain.
note : code below is in comment written just for understanding
thank you in advance.
Your code isn't formatted, probably an accidental mistake. It's just very difficult to read, so please edit.
Check now is it okay actually i am new so i don't know how to post formatted question
Answer by Happeloy · May 16, 2018 at 10:22 AM
A less confusing way to rotate an object than to edit its euler angles is to use the transform.Rotate(Vector3 angle).
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
void Update()
{
// Rotate the object around its local X axis at 1 degree per second
transform.Rotate(Vector3.right * Time.deltaTime);
// ...also rotate around the World's Y axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
}
(Read more here: https://docs.unity3d.com/ScriptReference/Transform.Rotate.html)
thank you for reply but my concern is not to rotate the object but to understand how eulerAngle works and why it cant exceed 90 degreee in above code thank you