Keep rotation from dipping below/above values

Hello!
I’m trying to keep a very basic vehicle from turning too far (to keep it from flipping over)

Here’s the code I have for that

transform.eulerAngles = Vector3((Mathf.Clamp(transform.eulerAngles.x, -45, 45)),transform.eulerAngles.y,(Mathf.Clamp(transform.eulerAngles.z, -45, 45)));

Although it just causes the vehicle to jump around.
What would be the correct way to do this?
Thank you.

Use Vector3.Dot(Vectr3.up, transform.up) to find how tilted the car is. If this is less than 0.5, then use Quaternion.LookRotation(transform.forward, Vector3.up) to create a new Quaternion “correctRotation”. Use Quaternion.Slerp to interpolate your current rotation towards “correctRotation”. Do this each frame with an interpolation amount of something low (like 0.01) and you should get a smooth correction of the vehicle rotation upwards. Adjust value to fine tune. If you want pure clamping, then use AmgleAxis to create 45 degree rotation along transform.forward to get correct rotation.

Sorry if it’s a bit brief, but I’m on mobile. May have overlooked something but that approach should work for you. Usually get better results with Quaternion functions rather than messing with Euler angles.

Dude you’re the best! Thanks so much!