Wheel input controller

I wrote the code to simulate the coil (like spinning), just rotate the mouse stripe, then there is no problem, but I need to rotation clockwise increases the value, and against - decreased. help me please.:frowning:

 Vector3 pos = ReferenceCamera.WorldToScreenPoint(transform.position);
        pos = Input.mousePosition - pos;
        float ang = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(ang, Vector3.forward);
     
        Value += ((int)(mPrevAng - ang));  <----------

such as here

I don’t understand what the problem you are asking about. What are the results of this code, and how is this different than what you want?
(It looks like English is not your first language, so this is fine, I’m just not sure what you’re asking.)

My best guess is that you are having a problem when it loops around from 360 to 0, is that right?

1 Like

Yes, at this moment. Аny ideas?

You just have to prepare for that specific case, and “loop” around for it. I like to use 180 degrees as a line - if the value changes by more than that, they’ve looped around.

This will probably work:

if (mPrevAng - ang > 180f) {
 Value += ((int)(mPrevAng - ang)) - 360;
}
else if (mPrevAng - ang < -180f) {
 Value += ((int)(mPrevAng - ang)) + 360;
}
else {
 Value += ((int)(mPrevAng - ang));
}

it makes sense,
but it does not fix the error, the value decreases at 180-0, and increases at 180-360

I may have gotten those backwards.

oh worked, thanks a lot)