- Home /
Random.onUnitSphere Hemisphere?
I am working on an AR game that includes ships spawning and moving towards the planet at the center. Everything works fine; however, I don't want the Prefab ships spawning within a negative Y coordinate.
My spawn line is:
Instantiate(spawnObject, Random.onUnitSphere * 20, Quaternion.identity);
Is there any way that I can have them spawn on more dome around the planet that is floating not far from the table surface? I don't want the ships spawning below the planet. Thank you for any help - I am rather new to C#!
Answer by Bunny83 · Mar 23, 2016 at 05:33 PM
There has been similar questions like this in the past:
http://answers.unity3d.com/questions/58692/randomonunitsphere-but-within-a-defined-range.html
If you need my answer over there in C# (which i usually use) just leave a comment ^^.
Answer by Cleverlie · Aug 25, 2017 at 08:07 PM
you can just do this:
var rand = Random.onUnitSphere;
rand.y = Mathf.Abs(rand.y);
that way all points will be on the top hemisphere
Your answer
![](https://koobas.hobune.stream/wayback/20220612072950im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Having Trouble with Instantiating an object on an axis 2 Answers
How Do I Add An Instantiated Object To An Array? 3 Answers
How would I create a script that spawns objects more frequently as time goes on? 3 Answers
Problems with spawning items that the players can pick up - Unet 0 Answers