- Home /
how to know if an axis has been full rotated?
I dont know how to get this done...
I rotate a object around its Y axis.(via mouse but that is not important)
I have a java script on that object that reads the actual localRotation.eulerAngles.y.
I need to know how often it is rotated around its axis. but if it gets over 359 it sets itselfe to 0 and backwards. If the var could get over 360 degree or under -360 that would help...
How are you rotating it? If a single script is doing the rotation, then just save the rotational value in a script (i.e. don't read it from eulerAngles). It is difficult to give you a specific instruction without see your rotation code. You can also count the times the forward vector flips from front to back using Vector3.Dot or Vector3.Angle.
I want to create a combination lock for a save ingame and I want that the player needs to move its mouse in a circle to dial the correct code. I found a solution to that. I use the mouse XY coordinates to move a empty in a vector 2 matrix around that is aglined to the combination lock. the distance of the empty is clamped so it cannot be somewhere else. in the center of the lock is also a empty that has a transform.LookAt that looks at the other empty.
in my other script I read that rotation of that lookat empty and apply it to my visible dial objects z axis.
Answer by Harry64 · Aug 10, 2014 at 10:32 PM
hah I found a solution!!! In my case I convert the eulerAngles to numbers from 0 to 99. but it can also be done if using degrees.
var diffOfRot : int = 0;
if(oldRotOfDial > newRotOfDial)
{
diffOfRot = oldRotOfDial - newRotOfDial;
if(diffOfRot > 50)
if(fullRotations != 0)
fullRotations++;
}
if(oldRotOfDial < newRotOfDial)
{
diffOfRot = newRotOfDial - oldRotOfDial;
if(diffOfRot > 50)
if(fullRotations != -4)
fullRotations--;
}
I simply make in my update function a var at the top that saves the current rotation before it will be changed in this update function. and because the rotation goes from 359 to 0 or 0 to 359 ( in my case from 99 to 0 and 0 to 99) I can make these if conditions that calculate if the difference is too high then a full rotation has happen and I can also see in which direction it was rotated. still there is a bug if the rotation starts at 0 and I would rotate backwards then it would say I rotated -1 but in my case this does not bother me.
Your answer
Follow this Question
Related Questions
Mathf.Clamp acts strange when going below 0 1 Answer
Need help with rotation script. 1 Answer
Rotating Player Controller locally or globally. 0 Answers
Object wont rotate in the opposite direction 1 Answer
Instantiate a rotated object 4 Answers