- Home /
using a custom rotation in "Instantiate"
I'm calling a GameObject to load at a specific point. I originally called it like this:
building = Instantiate(farmingPlot, farmPosition, transform.rotation );
However I need it to rotate 45 degrees in the x axis. Therefore I tried calling it like this:
building = Instantiate(farmingPlot, farmPosition, (transform.rotation.x-45,transform.rotation.y,transform.rotation.z) );
This is not working though. Does anyone know how I can do this?
Answer by robertbu · Feb 15, 2013 at 05:12 PM
You don't want to be using the x,y,z and w values of a rotation directly unless you really understand Quaternions. In fact, I'm surprised this compiled. Use Quaternion.Euler() instead:
building = Instantiate(farmingPlot, farmPosition, Quaternion.Euler(Vector3(45, 0, 0)));
This will give an absolute rotation of 45 degrees. If you want it relative like you have it, you can add transform.eulerAngles.y to the value.
Answer by Orami · Aug 25, 2015 at 02:53 PM
I wanted to update this since I came across it if you put the Vector3 call in the Quaternion.Euler call your code will not compile. Just drop the Vector3() portion off and your golden. See documentation: http://docs.unity3d.com/ScriptReference/Quaternion.Euler.html
Answer by abrakadabra · Mar 14, 2016 at 10:48 AM
I was looking for my problem too, and what I wanted to just rotate 90 degrees when I look just straight to sprite. It was Z instead of Y axis.
Instantiate (fish, spawnPosition, Quaternion.Euler(new Vector3(0, 0, -90)));
Answer by MakoBec · Oct 02, 2014 at 12:44 PM
var spawnTemp = Instantiate(prefab, gameObject.transform.position, Quaternion.Euler(270, 0, 0));
Your answer
Follow this Question
Related Questions
Rotate an Object 1 Answer
Link object rotation to its parent 1 Answer
Rotating an object in position 2 Answers
How do you flip a card with smooth rotation? 1 Answer
Trying to rotate and move a gameobject through JavaScript, help? 1 Answer