- Home /
a variable that when an object is tilted 0º = 0 and 90º = 1
sounds simple, i know the math to do that. divide the rotation by 90 and you get it. anyway there is one problem with this: if the object tilts, for example, 15º on the x axis it would work, but if it tilts 15º in the oposite direction on the same axis the rotation will be something like 375º, and dividing this by 90 will certainly give me a number over 1. i need a way for it to give me a number between 0 and 1 regardless on the direction it tilts. and i certainly dont know how to do that math. ill keep on trying to achieve it but certainly a hand would be much apreciated. thanks to all.
p.s. if i was not clear on my explanation, which i probably wasnt, feel free to coment me or edit the post if u think there is a better way to explain it. thanks a lot for all your help, and happy new year.
So what do you want to return for an angle of 180' or 270'?
that's sine isn't it?
$$anonymous$$ath.sin
assu$$anonymous$$g you want a smooth oscillation, sin90 is 1, sin0 is 0, the other answers provide a more linear output
you are right, i think i will use that. it is briliant and simple. happy 2014
Answer by ArkaneX · Jan 01, 2014 at 12:38 AM
I guess the easiest option is just checking if your rotation for a given axis is greater than 180 and in this case subtracting it from 360. C# sample for x axis:
float rotation = transform.eulerAngles.x;
if (rotation > 180f)
{
rotation = 360f - rotation;
}
float tilt = rotation / 90f;
This sample will return values over 1 for rotation greater than 90 and lower than 270, but you can tune the sample to take this into consideration. Or if such angles are impossible in your case, then you can leave the sample as it is.
thanks dude, i had thought of using if satatements, though not in this way. now it seems realy simple. thanks a lot again and happy 2014
Answer by HappyMoo · Jan 01, 2014 at 12:52 AM
float magicNumber = (180-((angle+180)%360))/90;
Now this gives -1 to 1 (for -90 to +90) in case you also want to know the direction. If you don't care about direction, slap a Mathf.Abs() around the formula.
Your answer
Follow this Question
Related Questions
Rotate object based on another rotation above a certain threshhold 1 Answer
gameobject stops moving correctly when rotating 1 Answer
Smooth rotation about global axis instead of local axis. 1 Answer
The object turn but the axis dont (SOLVED) 3 Answers
I need Some Info About Rotation And Pvot 0 Answers