- Home /
Rotating gameObjects gives me completely inaccurate values at runtime
I have my camera at 0,0 , -10 , and I want some gameObjects to be instantiated at even distances between each other around the screen, in the shape of a circle. This works. But when I want all of them to rotate, to point at the middle of the screen, they get weird values and none of them are correct. For example, one building has the rotation x :353, y: 153, z: 153, another one has x: 331, y: 126, z: 126. Can you help me out, I would go on and focus on something else but I like finishing stuff in advance before doing other stuff. I want the Y and Z to be at 90 degrees, and just X to change depending on the building itself.
for(int i=1; i<=buildingButtonAt.Length ; i++){
Vector3 location = new Vector3(
Mathf.Sin (((2*Mathf.PI)/buildingButtonAt.Length)*i)*8,
Mathf.Cos (((2*Mathf.PI)/buildingButtonAt.Length)*i)*8,
9);
Quaternion rotation = new Quaternion(
(Mathf.Rad2Deg)* (((2*Mathf.PI)/buildingButtonAt.Length)*i),
90.0f,
90.0f,
0.0f);
buildingButtonAt[i-1] = (GameObject)Instantiate (Resources.Load ("Building"),location,rotation);
}
It's hard to understand what you want to achieve. Please be more specific and detailed :)
I've been trying to do something like this http://imgur.com/orBSSzp . I'm referring to the gameObjects that have the black arrow on green transparent material. This has been done by manually arranging them, because they go into wacky directions. I have managed to make it 1 $$anonymous$$ute ago, repsonding on the answer section
Are you sure you understand how Quaternions work. It seems you are trying to construct one using degrees... that does not work. use Quaternion.Euler
if you want to get the quaternion equivalent of Euler rotation :)
Answer by Clw · Jun 30, 2013 at 12:08 PM
I've set the default rotation on instancing the game object to (0,0,0,0), and used the Rotate method like so to achieve the rotation :
buildingButtonAt[i-1].transform.Rotate (
360 -(Mathf.Rad2Deg)* ((2*Mathf.PI)/buildingButtonAt.Length)*i,
90,
90);
Your answer
Follow this Question
Related Questions
Instantiate an image, equally in a circle and rotate it away from the center? 2 Answers
Create plane from 2 Vectors of a symmetry line segment 1 Answer
Specify rotation of instantiated object 2 Answers
Rotation Problem 1 Answer
What would cause an objects transform to be different from its onscreen position? 1 Answer