Need help with rotation
Hey guys, i need a bit of help with my code. I have a speed indicator that rotates based on the levers rotation that is acually the one giving speed to my object. I am stuck on a trivial thing and cant solv it because im a nab dev and have little to no help..
My code for the indicator is really simple:
public class Speedmeter: MonoBehaviour
{
public Transform wheel;
void Update ()
{
transform.localRotation = Quaternion.Inverse(wheel.localRotation);
}
}
So what i'm doing here is just applying the rotation but in inverse.. just what i want.. but the thing is i dont want it to rotate the full 360 (340 in my case). I try'ed doing something like: ↓↓↓
transform.localRotation = Quaternion.Inverse(wheel.localRotation) * 0.1f;
but it cant be done (duh).. so can anyone teach me how i can limit the rotation of my speedmeter or tell it to rotate just by some percentage of the wheel?
Answer by Gotal · Nov 02, 2016 at 03:04 PM
Actually DID IT!
Here is the code, if anyone ever gets stuck and needs help with this.. i just assigned a new float that multiplies the angle value, hope it helps someone one day.
public class Brzinomjer : MonoBehaviour
{
public Transform wheel;
float yAngle;
float newAngle;
void Update ()
{
yAngle = wheel.transform.eulerAngles.y;
newAngle = yAngle * 0.5f;
transform.localRotation = Quaternion.Inverse(Quaternion.Euler(0, newAngle, 0));
}
}