Hi, long story short, I’ve been using unity on and off for a few years and stupidly enough keep finding myself coming back to have another shot at a failed project, every time I come back I usually have forgotten the formula to have a specific function happen in this instance it is that I wish to instantiate a Random object at a Random position with a little variation to the landing postion and have it rotate to a random rotation.
so the code I have is as follows:
void GenerateObject()
{
randTimeNum = Random.Range(minSpawnTime, maxSpawnTime);
randObjectNum = Random.Range(0, spawnableObjects.Length);
randDiffSizeX = Random.Range(minDifferSizeX, maxDifferSizeX);
randDiffSizeZ = Random.Range(minDifferSizeZ, maxDifferSizeZ);
randSpawnLocation = Random.Range(0, spawnLocations.Length);
newTrans = spawnLocations[randSpawnLocation].transform;
Debug.Log("RandTimeNum is now: <color=red>" + randTimeNum + "</color>.");
Debug.Log("RandObjectNum is now: <color=red>" + randObjectNum + "</color>. Which is: <color=green>" + spawnableObjects[randObjectNum].name + "</color>.");
newObj = Instantiate(spawnableObjects[randObjectNum], new Vector3(newTrans.position.x + randDiffSizeX, 0, newTrans.position.z + randDiffSizeZ));
newObj.transform.Rotate();
}
The issue I am having is on the last TWO lines of this function… for one I have forgotten the formula for setting my newly spawned object at a specified position + the little variation to stop a stack of objects being piled very neatly ontop of each other (and when I try and google search this it is either very poorly explained, or explained in a way that you have to figure out the rest of the forumla if you wish to add a variation, ie: https://forum.unity.com/threads/instantiate-object-at-another-object.285221/)
The other one is when I try and search ‘how to SET the rotation of an object’ all that returns is, Lets show you how to rotate an object by 1 every frame, or by 1 every second… I do not wish to have a spinning object! I wish to set the objects rotation to a random digit upon it spawning and physics to take over the rest as it hits the ground to have variation.
Thank you If answered I will bookmark this post so I can forever refer back to it as googling this question every time I return just leaves me with headaches and pulling my hair out as it returns a… “oh its simple you just use transform.position and it will work!” which for my case no, it will not simply work like that…