How do i instantiate a 3D object with a random y rotation?
Instantiate’s third parameter is starting rotation.
And if i try to change the y rotation, it doesnt work. can you give an example of how?
If it doesn’t work, then it’s because something has gone wrong- post your code to give us a better chance of being able to help you.
As for examples, you’ll find plenty of examples here on the Instantiate manual page.
General tips: typically when you’re instantiating an object you’re giving it a rotation relative to the current (or some other) object. That being the case, assigning it the current object’s transform.rotation or some transformation of that rotation is best. To use a quaternion that’s facing a specific direction in real-world coordinates, use Quaternion.LookRotation. If you want to rotate by degrees, don’t use the Quaternion’s “y” value (it’s not what you think it is)- use Quaternion.Euler instead.
Ok i got it.
here;s the code that worked for me:
Instantiate(object, transform.position, Quaternion.Euler(new Vector3(90, Random.Range(0, 360), 0)));
Obrigado’. Brasil aqui’.
its a bit late but how can I do this loccaly?
Might Work:
GameObject spawned = Instantiate(prefabToSpawn);
spawned.transform.localRotation = Quaternion.Euler(new Vector3(0, Random.Range(0f, 360f), 0));