One more question about vector3 rotation.

Hello all. Help me pls.
I have a vector3 that i use for throw velocity(calculatiog throw path).
I need to rotate thiw vector by two axis: X and Y(up\down and left\right).

How can i do this? I tried use rotation matrix but my results are wrong - my “float angle” before rotation != real angle(Vector3.angle(old, new)).
How can i easy rotate my vector? :-[

idk what do i wrong, but Vector3.angle(sourceVector, resultVector) are not equals with xDegrees for example with one axis(i used it with quaternion).

1 Answer

1

Construct a rotation using Euler angles or use two Quaternions

  var vec = Quaternion.AngleAxis(xDegrees, Vector3.right) * Quaternion.AngleAxis(yDegrees, Vector3.up) * sourceVector;

  var vec = Quaternion.Euler(x,y,0) * sourceVector;

Mb i do it wrong, but it dont work. > float dispersion = 2f; > Vector3 tmpVector = Quaternion.AngleAxis(dispersion,Vector3.right) > * sourceVect; > Debug.Log("real angle: " + Vector3.angle(sourceVect, tmpVector)); In log i see not 2;

What do you see? It shows ~2 for me (as accurate as a float is going to be)