object rotation simulation based on other two objects rotation. like changing frequency(anolog) in radio with two knobs

Here is the situation , i have two knobs and one frequency indicator. the rotation of indicator should be based on the rotation angle(value of rotation) of both the knobs . (say knobs are rotating in Y-axis, and indicator should rotate on X-axis )

Hi there !

First of I think if we follow the capture you attached that all the rotations can be done on the same axis. Unless your objects have a different rotation to start with.

Now in the case you want to set the INDICATOR rotation accordingly to one of the knob , and you want it to follow perfectly I would begin by placing them both at the same angle example:(Indicator vector3(0,0,90) and the knob vector3(0,90,0))

The calculation I would do afterwards would be to find the difference between both angles (note since you only rotate on one axis (different axis on the two objects but still a single value) we can use a float for this)

float offset = knob.transform.eulerAngles.y - indicator.transform.eulerAngles.z;

After this we simply have to add make the rotation accordingly to the offset we have between both angles like so :


Now lets say that you want your 2 knobs to affect together the indicator YOU will have to come up with the maths you want for it to work.
Here is a simple example: add the rotation of the two knobs together and divide by 2 in order to get the offset this time Like so :

float offset = (knob1.transform.eulerAngles.y + knob2.transform.eulerAngles.y) / 2 - indicator.transform.eulerAngles.z;

Here is a second example of how you could calculate this, you could use the offset float and simply multiply it by a smaller number then 1 but bigger then 0. It will basically act as a divider for your number. Like so:

float offset = (knob1.transform.eulerAngles.y + knob2.transform.eulerAngles.y) / 2 - indicator.transform.eulerAngles.z;
offset *= 0.5f ; <--- this is what I would do personally.

I would finish by adding limitations on the rotation of the knobs and indicator. The main reason is that the angle could be below 0 or over it with by example: The angle 270 and -90 being the same angle…

So MY final code would probably look like this:

//first set the variable names so we save on processing
Quaternion knob1Rot = knob1.transform.eulerAngles;
Quaternion knob2Rot = knob2.transform.eulerAngles;
Quaternion indicatorRot = indicator.transform.eulerAngles;

//if the angle Y is less then 0 , add the reverse of the missing angle to get 0 (ahhh maths)..
if (knob1Rot.y < 0) {knob1Rot.Rotate(0,-knob1Rot.y,0) }
if (knob2Rot.y < 0) {knob2Rot.Rotate(0,-knob2Rot.y,0) }

float maxAngle = 180; //I don't want MY knobs to rotate more then 180 degrees
if (knob1Rot.y > maxAngle ) {knob1Rot.Rotate(0,maxAngle -knob1Rot.y,0) }
if (knob2Rot.y > maxAngle ) {knob2Rot.Rotate(0,maxAngle -knob2Rot.y,0) }

//now that the knobs are not outside of their limits I would set the rotation of the indicator:
float offset = (knob1Rot.y + knob2Rot.y) / 2 - indicatorRot.z;
offset *= 0.5f ;

/*and If you really have processing power to loose but want to MAKE SURE that the rotation of the indicator is not off limit , just do the same as the knobs limitation :*/
if (indicatorRot.z < 0) {indicatorRot.Rotate(0,0,-indicatorRot.z) }
if (indicatorRot.z > maxAngle ) {indicatorRot.Rotate(0,0,maxAngle -indicatorRot.z) }

At this point you can really decide how the knobs affect the indicator by yourself !

I hope this will be usefull , maybe not all the information there will be good for you but I hope at least a part of it is !