Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity, rotating a Vector3 along an axis

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?


1 Answers

You can 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;
like image 133
TheNomad Avatar answered Sep 05 '26 11:09

TheNomad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!