i made levers to show their rotations above them and default rotations are 90 degrees
but when i rotate them with raycast …it just decrease from 90 degrees not up to 90…as you see :
and here is my code:
using UnityEngine;
using TMPro;
public class sifreyazi : MonoBehaviour
{
public TextMeshPro s1;
public GameObject st1, st2, st3, st4, st5, st6;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float x1 = st1.transform.eulerAngles.x;
s1.text = x1.ToString("0");
}
}
Well we have no idea about the orientation of your levers in space. Is the worldspace x axis even the axis of rotation?. How do you actually rotate your object? Is the rotating object a child of another object? If so why don’t you read the localEulerAngles?
Also keep in mind that Euler angles have countless of issues. Specifically Unity uses the Y-X-Z order. Unity also does not work with euler angles internally but uses quaternions which mostly avoid all the issues that euler angles have. That means the euler angles are calculated from the actual orientation of an object.
When the X euler angle in this configuration is 90° you are actually in the gimbal lock position. If you only rotate on the X axis this isn’t that important, however the X rotation is only specified in the range +-90° anyways. It’s the objects “pitch” (when using aviation angles / terms). The yaw rotation (y rotation) and the roll rotation (z rotation) is in the range +-180°. The eulerangles is an overspecifed system. So it doesn’t have a unique representation of a certain orientation.
For example the orientation (0,0,0) is the same as (180,180,180). Likewise if your rotation is (105,0,0) it is the same as (75,180,180). In general you shouldn’t really rely on euler angles since they might not represent what you want them to represent.
Though when using a parent object and you only rotate the child object you should have no issues with local rotations if the parent already applies your offset. So have the parent rotated x =90° and the child rotate between -15° and 15° if that’s the angle you’re looking for.
In a more general sense such a thing as a lever position should actually be seperated from the visual representation, at least if you want to do some logic on that state.
Since we don’t know anything about your usecase we can’t really suggest any alternatives.