Hello. I am making something like old FM radio.
There is a wheel that can be rotated with mouse. Here is the code how I rotate it:
mouseClickPos = Input.mousePosition;
Vector3 dir = mouseClickPos - Camera.main.WorldToScreenPoint(transform.position);
angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
angle-=90;
angle = Mathf.Round(angle/6.0f)*6.0f;
Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
hand1.transform.rotation = Quaternion.RotateTowards(hand1.transform.rotation, q, 6);
Now there is an arrow that needs to be moved on y axis from -4 to 4 when wheel is rotated. The arrow starts in 4, and when wheel is rotated to the right, arrow needs to go towards -4 point. And when it reaches -4, it needs to go back to 4 while wheel is rotated in same direction as from beginning. If player starts to rotate wheel to the other side (left), the arrow needs to start moving to the other side from the side it was going until then. I did try something like this but it is not working:
a1 = Mathf.Floor(oblaci.transform.localRotation.eulerAngles.z);
if(arrow.transform.localPosition.y >= 4.0f)
{
arrowUp = !arrowUp;
}
else if(arrow.transform.localPosition.y <= -4f)
{
arrowUp = !arrowUp;
}
if(a1>a2)
{
if(arrowUp)
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y+0.0061111111f, arrow.transform.position.z), 1.0f);
}
else
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y-0.0061111111f, arrow.transform.position.z), 1.0f);
}
}
else if(a1<a2)
{
if(arrowUp)
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y-0.0061111111f, arrow.transform.position.z), 1.0f);
}
else
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y+0.0061111111f, arrow.transform.position.z), 1.0f);
}
}
a2=a1;
Something like that. The problem is that when arrow reaches bottom while i am pulling mouse down, it should go up agan, not stand in bottom.
– oxa89http://www.westwalescse.net/unity/radio/radio.html try this again I've changed it, although it is odd behaviour for a radio imo... :D
– bubzyI said I am making "something like radio" :) Thx for your work, but it's my mistake, I explained it poorly. When arrow reaches bottom, it should start moving towards the top, not just start from top again. Here is the picture how should it go[34094-untitled.png|34094] While scrolling the wheel, arrow first goes towards bottom, then when it reaches bottom, it should start moving towards top (2.), and then again towards bottom (3.). But this example could be useful. Can I please get the zip?
– oxa89when I get home from work :)
– bubzy