So the angle goes from 180 to -180 and I want it to go from 0 to 360, but it just doesn’t want to cooperate and I don’t know what i am doing wrong.
IMAGE HERE
Imgur: The magic of the Internet .
Code in text:
public GameObject m_Player;
public GameObject m_PivotTarget;
public GameObject m_BatTarget;
public bool m_IsAttacking = false;
float m_CurrentAngle = 0f;
float m_PreviousAngle;
float m_NewAngle = 0f;
[SerializeField] float m_Smoothing;
// Start is called before the first frame update
void Start()
{
m_PreviousAngle = m_NewAngle;
}
// Update is called once per frame
void Update()
{
Vector2 vector = Camera.main.ScreenToWorldPoint(Input.mousePosition) - m_Player.transform.position;
float radiants = Mathf.Atan2(vector.y, vector.x);
m_NewAngle = radiants * Mathf.Rad2Deg;
m_CurrentAngle = Mathf.Lerp(m_PreviousAngle, m_NewAngle, Time.deltaTime * m_Smoothing);
gameObject.transform.rotation = Quaternion.AngleAxis(m_CurrentAngle, Vector3.forward);
m_PreviousAngle = m_CurrentAngle;
}