I’ve 4 dials that rotate by increments when the gamers drag them. All of them precisely have the identical code, however I can not determine why solely one of many dial works as supposed (dial 1). My code stops working as supposed on different dials once I change the increment rely to 4, the opposite dials rotate 1 / 4 after which stops to maneuver once I drag them.
Here is my code
public static float DegreesCCWFromRight(Vector2 middle, Vector2 pointer)
{
var course = pointer - middle;
return Mathf.Atan2(course.y, course.x) * Mathf.Rad2Deg;
}
//v2 rotate with incremental snapping
personal void RotateObject()
{
Vector2 worldPoint = Digital camera.fundamental.ScreenToWorldPoint(Enter.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector3.ahead);
if (Enter.GetMouseButtonDown(0))
{
if (hit.collider && hit.collider.GetComponent<Rotate2d>())
{
previousRotation = DegreesCCWFromRight(rework.place, Digital camera.fundamental.ScreenToWorldPoint(Enter.mousePosition));
}
}
else if (Enter.GetMouseButton(0))
{
if (hit.collider && hit.collider.GetComponent<Rotate2d>())
{
currentRotation = DegreesCCWFromRight(rework.place, Digital camera.fundamental.ScreenToWorldPoint(Enter.mousePosition));
previousRotation = currentRotation;
Vector2 mouseWorld = Digital camera.fundamental.ScreenToWorldPoint(Enter.mousePosition);
float angle = DegreesCCWFromRight(rework.place, mouseWorld);
const float incrementCount = 4;
angle = Mathf.Spherical(currentRotation * incrementCount / 360)
* 360 / incrementCount;
hit.collider.gameObject.rework.localEulerAngles = new Vector3(0, 0, angle);
}
}