Hi, I am trying to use smoothDamp to get a smooth 2D rotation going but I can’t seem to get the code right… Any help would be very appreciated!
using UnityEngine;
using System.Collections;
public class smoothCheck : MonoBehaviour {
public Vector3 diff;
public float rot_z;
public float smoothTime = 0.3f;
private float yVelocity = 0.0f;
private float newPosition;
void Update () {
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
diff.Normalize();
rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
rot_z = rot_z - 90;
float current = transform.eulerAngles.z;
newPosition = Mathf.SmoothDamp(current, rot_z, ref yVelocity, smoothTime);
transform.rotation = Quaternion.Euler(0.0f, 0.0f, newPosition);
}
}
It seems like the rotation only works in quadrant 2 but not in quadrant 1,3,4. I am not sure what I am doing wrong…