- Home /
Transform.rotation problems
**H**ello. I can't insert GameObjects atached to an script of other GameObjects with the correct rotation:
The structure of whole thing is: An script atached to GameObjects 'parede'(wall), inside this script I have a function called insereRevestimento()(something like insert lining that insert gameObjects in this wall).
GameObject parede-->paredeProperties.cs-- >insertLining();
public class PropriedadesParede : MonoBehaviour {
public GameObject revestimento;
insertLining(){
revestimento.transform.position=new Vector3(pontoInicialX+
larguraDoRevestimento/2 +larguraInserida,
pontoInicialY+comprimentoDoRevestimento/2 +comprimentoInserido,
transform.position.z+revestimento.transform.localScale.z*2);
// --> This part:
revestimento.transform.Rotate(0,90,0);
Instantiate(revestimento);
revestimento.transform.Rotate(0,90,0);}
}
The natural rotation is (0,0,90) so I thing it must give for me the result (0,90,90), but it returns (-0.0005,270!,93). I am questioning me if the rotation of GameObject that the script is attached is affecting the final result, despite of the fact if I instantiate without Rotate the angle keeps the original, without interference. If is it, there is a way to rotate based on the angle global standard?
Have you tried instantiating it WITH a position and rotation.
Instantiate(GameObject,Vector3,Quaternion); <---
Answer by jogo13 · Dec 24, 2012 at 06:02 PM
You are instantiating a new Gameobject but not 'capturing' the returned new gameobject: Try this:
GameObject newGO = Instantiate(revestimento) as GameObject;
newGO.transform.Rotate(0,90,0);
You may want to use '`tranform.EulerAngles`' instead of Rotate http://docs.unity3d.com/Documentation/ScriptReference/Transform-eulerAngles.html
Sorry it does not work,
I tryed: GameObject instanciaRevestimento = Instantiate(revestimento) as GameObject; instanciaRevestimento.transform.Rotate(0,90,0);
with a natural prefab with properties (0,0,90) so I think result must be (0,0,90) but it's setting (270,0,90)
this should work: instanciaRevestimento.transform.rotation = revestimento.transform.rotation;
Your answer
Follow this Question
Related Questions
rotate to swip direction 0 Answers
C# Rotate GameObject at Other Point other than Center 3 Answers
RaycastAll isn't finding all possible collisions 1 Answer
How get the rotation of an GameObject? 3 Answers