- Home /
Quaternion.AngleAxis() is alway using the axis at 0, 0, 0
I want to calculate different points around a object. To do this i'm using Quaternion.AngleAxis(). But the points always gets calculated around 0, 0, 0 as you see in the picture below. Here is the code:
for (int i = 0; i < numberOfRays; i++)
{
Quaternion rotation = this.transform.rotation;
Quaternion rotationMod = Quaternion.AngleAxis((i / ((float)numberOfRays - 1)) * angle * 2 - angle, this.transform.forward);
Vector3 dir = rotation * rotationMod * Vector3.right;
rayDirections[i] = dir;
//Instantiate(emptyGameObject, rayDirections[i], Quaternion.identity);
}
And here the picture what is happening (visualized with empty gameObjects):
So the black guy is the gameObject the points should be around. Hope somebody can help me. Maybe i don't understand Quaternion.AngleAxis() right. I'm by the way using sprites of Archvale as placeholder sprites. So defenetly go and check IDoZ Devlogs out: https://www.youtube.com/watch?v=hDxxKNS55Cg&list=PLokUXxE68Y2nQ5ufDEnEi4fqgSqY1mrxX
Answer by jackmw94 · Feb 05, 2021 at 10:29 AM
I think you're creating the rotated offsets alright, you just need the positions to be local to the player. So if this is a child of your player then you want to be setting their local positions:
var newObj = Instantiate(emptyGameObject, Vector3.zero, Quaternion.identity);
newObj.transform.localPosition = rayDirections[i];
Or if they are separate to the player then they'll need a reference to his position in order to place themselves around him:
rayDirections[i] = dir + player.transform.position;
With player being a reference to your player gameobject or a component on your player.
Let me know how you get on with this or if I've misunderstood something :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613024616im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotation-projection to new coordinate system 1 Answer
Rotation with different speed for different axis 2 Answers
Rotating tank barrel on X axis while the parent Turret rotates on Y axis 2 Answers
Rotation from AngleAxis() ToAngleAxis() flips back and forth 1 Answer
transform.right = (point on axis) after using LookAt? 2 Answers