I am trying to understand quaternion.euler. I have read the docs and still don’t really follow what it is meaning.
I seen a piece of code which has this Dir = Quaternion.Euler(new Vector3(0,90,0)) * oldDir;
The oldDir seems to be a vector3 of 0.5, 0, 0.5. So what does this calculation actually do? Ive debug.log the results and seems to print 0.5,0, -0.5 but do not understand how this is correct?
Hi, Thanks for the reply. So does that mean rotate each element of V by the rotation of Q? so each element V would be rotated by 90? And in that case should the code I am testing out not producing 45, 0, 45 and not 0.5 0. -0.5?
I think you have an incorrect idea about what V is (or should be), because this question is hard to make sense of. In your original post you say that V “seems to be a vector3 of 0.5, 0, 0.5”. That means that it represents a point in space that is half to the right and half a unit forward of the origin. This may also be used to represent a direction, e.g. the direction from the origin through the point described. Since it’s called oldDir, that’s probably what its intention is.
The only way I can make sense of your question here is if you think that this Vector3 represents a rotation that is rotated by 0.5 degrees around each axis (that is, Euler angles). In context, this is one thing that oldDir definitely doesn’t represent, because the math operation shown here is nonsensical for those values.
What the original line of code posted is doing is taking that point in space (0.5,0,0.5) and rotating that point around the origin by 90 degrees, as if that point was a spot on a record turntable. (With that image hopefully you can see why the question doesn’t make sense as asked - rotating “each element” of that point in space doesn’t do anything that makes sense.) That’s how it ends up at the point you’re seeing in your debug log.
Uhm, no ^^. A vector points into 3d space. It can define a direction or a point in space. When you rotate a vector it is rotated around the origin (0,0,0). While a vector is always just a vector, a direction vector simply encodes the relative offset in the x, y and z direction. A point is essentially just a different view of the same thing. A point is not just a direction with a certain length but is relative to some coordinate space. A world space point is relative to the world origin while a local point would be relative to the pivot of the parent object and also expressed in the local space of that object.
That’s just some basic linear algebra stuff. If you have trouble understanding what a vector is, I would highly recommend the 3B1B series on linear algebra because vectors are one of the fundamental building blocks in game dev and 2d / 3d. Don’t get scared by the first summary video
Imagine you have a vector that is (4,2,7). So a vector that goes 4 units in the x direction, 2 units in the y direction and 7 units in the z direction. The quaternion you created represents a rotation around the y-axis by 90° clockwise. So rotating our vector would result in (7,2,-4). When you rotate around the y axis, the y component stays unchanged because we rotate in a plane that is perpendicular to that rotation axis. So the only values affected are the x and z components in our example here.
First of all thank for you all responding. Now that it has been mentioned I am beginning to remember vector stuff, and can see now why my question did not make a lot of sense. Unfortunately I am still finding it difficult to picture the rotation etc in my head to see where the values come from, but will watch the playlist that Bunny linked, and hopefully that will help out.