- Home /
How get angle for full rotation
Hello everyone! Here is the problem: there is an object that rotates only along one axis (x, y or z) and this axis is parallel to the world axis. The starting angle can be any. How to calculate the time for which the division of the changing angle by 90 becomes 0 (ie, all the local axes of the object become parallel to the world axes), given the angular velocity (may be negative).
Here's a video to make it clear why I need it: Test
This is the code I thought of writing, but it does not work correctly:
public static float GetAngleForCompliteRotation(Transform target, Vector3 rotationAxis, Rigidbody rb)
{
float deltaAngle = 0;
if (rotationAxis == -Utilites.RoundVectorTo(target.right, 1) ||
rotationAxis == Utilites.RoundVectorTo(target.right, 1))
deltaAngle = rb.rotation.eulerAngles.x;
else if (rotationAxis == -Utilites.RoundVectorTo(target.forward, 1) ||
rotationAxis == Utilites.RoundVectorTo(target.forward, 1))
deltaAngle = rb.rotation.eulerAngles.z;
else if (rotationAxis == -Utilites.RoundVectorTo(target.up, 1) ||
rotationAxis == Utilites.RoundVectorTo(target.up, 1))
deltaAngle = rb.rotation.eulerAngles.y;
return deltaAngle % 90;
}
Your answer
Follow this Question
Related Questions
local rotation per axis between frames? 1 Answer
Check if rotation (only on Y axis) of some object toward another is finshed? 0 Answers
How to use the lerp function with rotation? (C#) 1 Answer
How do I add force to an object based on my Camera's cureent Y rotation (C#) 2 Answers
rotation x changes all angles? 3 Answers