How can I do a smoothly Rotation?


I have a Code from
After some changes the code make a rotation, when you turn your smartphone like in real world position.
My Problem is, that the frame woobles a lot.
I don´t understand the Coroutine right.

Can Anyone help me?


public class compass_Kopie : MonoBehaviour {
float degree;
float degree_round;
public TextMesh Status_Text;

// Use this for initialization
void Start () {
	Input.compass.enabled = true;
	Input.location.Start ();

   // Update is called once per frame
void Update () {
	StartCoroutine (Example ());

public void Berechnung(){
	//Berechnung Winkel
	var xrot = Mathf.Atan2 (Input.acceleration.z, Input.acceleration.y);
	var yzmag = Mathf.Sqrt (Mathf.Pow (Input.acceleration.y, 2) + Mathf.Pow (Input.acceleration.z, 2));
	var zrot = Mathf.Atan2 (Input.acceleration.x, yzmag);
	var zangle = -zrot * (180 / Mathf.PI);
	degree = Input.compass.trueHeading - zangle;
	var degree_round1 = degree / 10;
	var degree_round= Mathf.Round (degree_round1)*10;

	if (Status_Text != null) {
		Status_Text.text = degree_round.ToString ();
	transform.eulerAngles = new Vector3 (0, degree_round, 0);
IEnumerator Example(){		
	yield return new WaitForSeconds (1000);


You can use Mathf.SmoothDamp().
link: Unity - Scripting API: Mathf.SmoothDamp

Use this to smoothly rotate the values you receive from the accelerometer


Thank you for you answer! It works a little bit better, but not perfectly!

I have done:

float newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y, ref yVelocity, smoothTime);
transform.eulerAngles = new Vector3 (0, degree_round, 0);

Is it correct?

If it is between two numbers, the display rotate to much!