Issue with Euler angles

I have a vehicle with wheels.I need to rotate the 2 wheels for specific angles. Let’s say, the user inputs the angle as 45 degrees, the wheels must rotate 45 degrees and stop. I am using AddRelativetorque to push the wheel. I am stuck with the issue of euler angles as x axis only moves from 0-90-0-360-270-360-… kind of like oscillating between 90 and 270. Can someone help me with this please?.

If you want to track angle change over time you can’t just read the Euler Angles every frame. I will try to briefly explain why, but you can skip to the end if you just want the solution.
**
Rotations are stored as Quaternions in Unity. Quaternions are just a fancy mathematical form for rotations. You don’t need to know how a Quaternion works, but what you DO need to know is that for every possible rotation there is exactly ONE corresponding Quaternion. The problem with Quaternions is that they are hard to make sense of for a layman. When you look at a rotation in Unity you want to be able to tell what the rotation is around each axis, so Unity gives you the ability to grab the Euler Angles out of a Quaternion. Whenever you ask for rotation.eulerAngles, Unity converts the Quaternion representation into an Euler representation. One of the problems with Euler Angles, though, is that for any given rotation there are INFINITE different Euler representations. Some of these are easy to see, for example (0, 0, 0) is obviously the same as (360, 0, 0), but there are also more complicated equivalent rotations as well. When Unity gives you the Euler Angles, it tries to give you the simplest Euler representation it can, however, and this means that if you are querying for Euler Angles every frame you cannot rely on the Euler Angles themselves always following each other. For a small change in rotation, Euler Angles can still vary wildly.
**
So what can you do, rather than tracking the euler angles every frame? Instead, just read the Euler Angles of the change in rotation. Track the rotation from the previous frame, then compare it to your current rotation to get the delta rotation, then you can pull the Euler Angles to get the overall change in rotation. (Note that this will only work if the change in rotation per frame is relatively small).

private Quaternion prevRotation;
private float totalRotationAngleX;

void Update(){
    Quaternion deltaRotation = transform.rotation / prevRotation;

    float xAngleThisFrame = deltaRotation.eulerAngles.x;
    totalRotationAngleX += xAngleThisFrame;

    prevRotation = transform.rotation;
}

Turn my wheels to move forward.

If you want to turn your wheels a set number of degrees, use quaternions rather than euler angles. These are used to avoid gimbal lock (where your euler axes align), awkwardness with degrees wrapping around (i.e. trying to move from 320 degrees to 10 degrees and taking the long route) which might be your problem here and also using the quaternion functions make the code easier to read.

I believe the function you’ll need here is AngleAxis, this takes arguments for the number of degrees and the axis around which to rotate.

// rotate 45 degrees around x axis:
transform.rotation = Quaternion.AngleAxis(45, Vector3.right) * transform.rotation;

A quaternion is a description of a rotation so this code will rotate your transform 45 degrees around the global right axis wherever it starts from. Have a look at the other static functions in the quaternion class as they’re good to have in your toolbox for problems like these.