Home > Enterprise >  Unity, rotating a Vector3 along an axis
Unity, rotating a Vector3 along an axis

Time:12-23

For example, I have a Vector3 and I waant to rotate it relatively Y-axis (Vector3.up). Can I do it using built-in methods, or should I use coordinate geometry and trigonometry?

CodePudding user response:

You need to use Quaternions to rotate vectors.

For example, to rotate a source vector by 30 degrees the way you want, you can use AngleAxis() :

Vector3 v = Quaternion.AngleAxis(-30, Vector3.up) * sourceVect;

CodePudding user response:

Transform.RotateAround(Vector3 point, Vector3 axis, float angle) rotates a transform about an axis. In your instance, the axis would be Vector3.up or new Vector3(0, 1, 0).

  • Related