- Home /
how to find way of rotation
how do i track the way the character rotates. and what speed it rotates in. like i wanna track if it goes up down left or right,how do i track my rotation so that it knows what way it goes. i tried but i couldnt do it without anything else then the position value
Answer by Quatnu · May 31 at 08:41 PM
I don't know your code or if your game is 3D or 2D but to find the direction it could be just:
if (transform.eulerAngles.z == 0) //Up (or you can setup bounds for the rotation – example: if (transform.eulerAngles.z > 350 && transform.eulerAngles.z < 10))
{
}
if (transform.eulerAngles.z == 90) //Right – example: if (transform.eulerAngles.z > 80 && transform.eulerAngles.z < 100))
{
}
if (transform.eulerAngles.z == 180) //Down
{
}
if (transform.eulerAngles.z == 270) //left
{
}
For determining the rotation speed, you can try this in void Update():
rotationSpeed = transform.eulerAngles.z - previousRotation;
previousRotation = transform.eulerAngles.z;
And this in void Start():
previousRotation = transform.eulerAngles.z;
but how could this work on others than the standard rotation
Answer by lexar1232015 · May 31 at 08:37 PM
Try creating a coroutine with a delay yield return new WaitForFixedUpdate();
and make it self-invoking. Each call write the value of transform.Rotation to a local variable and check what it was before. So you can calculate the speed and direction
but i have a question how do i save them in the right way i tried but i couldnt manage
Quaternion _lastRotation = transform.rotation;
do you now how i can check for what the value was a little while ago after a button press
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Inheritance in C# and Unity3d 1 Answer
Mouse targeting error 1 Answer
How do I seed the random number generator myself and still get pseudorandom values? 2 Answers