|
Post by britannis on May 22, 2016 9:39:29 GMT
There are plenty of rotation methods, but if I want to determine whether an object will rotate right or left in 2D space, how would I accomplish that?
virtual protected float GetRelativeAngle() { // Get relative angle. Vector3 up2D = new Vector3(myModel.transform.up.x, myModel.transform.up.y, 0); float relativeAngle = Vector3.Angle(up2D, myModel.GetCurrentLookDirection().normalized);
// Get relative sign. Vector3 relativeCross = Vector3.Cross(myModel.transform.up, myModel.GetCurrentLookDirection().normalized); if (relativeCross.z < 0) relativeAngle = -relativeAngle;
return relativeAngle; } GetCurrentLookDirection is where the mouse cursor is pointing, by the way.
The problem is that sometimes I'm getting a positive relativeAngle when rotating my object either direction.
How would you approach calculating whether an object will rotate left or right in 2D space?
|
|
|
Post by Admin on May 23, 2016 15:13:57 GMT
Is your question basically, "How do I know if a clockwise or counter-clockwise rotation is more efficient to take me from my current angle to a target angle?" I believe that Unity solves this problem for you if you use things like Vector3.Slerp or Quaternion.RotateTowards which should already take the most efficient path.
|
|
|
Post by britannis on May 23, 2016 20:19:24 GMT
Yes, but what I'm trying to do is get that direction (clockwise or counterclockwise).
I'm using it to play turning animations.
|
|