- Home /
Get direction of single axis from quaternion.
Hello. I have some trouble trying to offset a vector from a center point. I'm passing my object's position and rotation to my method and creating an offset vector 3 that points to the direction of it's corresponding axis. The problem is that when i try to multiply the offset vector3 by the rotation quaternion, The rotation is applied from the point which it's offset and the resulting vector flies around everywhere. Here's my code:
public static void DrawAxis(Vector3 pos, Quaternion rot)
{
var posX = pos + new Vector3(1, 0, 0);
DrawLine(pos, posX, Color.red, 2);
DebugDisplay.DisplayInfo(posX, "X");
var posY = pos + new Vector3(0, 1, 0);
DrawLine(pos, posY, Color.green, 2);
DebugDisplay.DisplayInfo(posY, "Y");
var posZ = pos + new Vector3(0, 0 ,1);
DrawLine(pos, posZ, Color.blue, 2);
DebugDisplay.DisplayInfo(posZ, "Z");
}
In my example code above no. As i said i tried doing rot*posX but this makes the vector fly off in the distance
If I'm understanding you I thinking what you are looking for is Quaternion.LookRotation
Sort of. What i'm actually looking for is rotating a vector3 point along a predeter$$anonymous$$ed point by a quaternion.
You mean you want an object to rotate around another object/point in space?
If so check out Transform.RotateAround
Your answer
![](https://koobas.hobune.stream/wayback/20220612200448im_/https://answers.unity.com/themes/thub/images/avi.jpg)