Comments and answers for "Random.Range Vector3"
http://answers.unity.com/questions/694692/randomrange-vector3.html
The latest comments and answers for the question "Random.Range Vector3"Answer by rhodnius
http://answers.unity.com/answers/1650136/view.html
Here is the code if someone is needing it:
using UnityEngine;
public static class MathUtilities
{
public static void Random(this ref Vector3 myVector, Vector3 min, Vector3 max)
{
myVector = new Vector3(UnityEngine.Random.Range(min.x, max.x), UnityEngine.Random.Range(min.y, max.y), UnityEngine.Random.Range(min.z, max.z));
}
}
You can use it just by having any vector field and calling from it Random(minVector, maxVector)Fri, 19 Jul 2019 21:12:58 GMTrhodniusComment by OtsegoDoom on OtsegoDoom's answer
http://answers.unity.com/comments/694723/view.html
@wibble82, I like your explanation. I never really thought about the min and max forming a box. Too bad there's no Unity function for this. I'll continue doing what I've been doing for now. I'll probably end up writing a utility function like you suggested since this seems to be something I do fairly often.Fri, 25 Apr 2014 17:30:44 GMTOtsegoDoomComment by MikeNewall
http://answers.unity.com/comments/694720/view.html
@roertbu I should read things properly :p Also I forgot about
Random.insideUnitSphere * radius;
which would give the same result as his code but with spherical bounds ins$$anonymous$$d of rectangular.Fri, 25 Apr 2014 17:26:44 GMTMikeNewallAnswer by wibble82
http://answers.unity.com/answers/694715/view.html
Your code effectively gives you a random position within a 'box', who's "min" corner is at minPosition and "max" corner is at maxPosition. There's no handy unity function to return you a random vector within a box unfortunately, however you could of course write your own little utility function to do it. Maybe create a class somewhere called 'RandomUtils', with a static function in called 'RandomVectorInBox'.
The Random.onUnitSphere, or Random.insideUnitSphere functions give you a random vector either on the surface of, or inside, a sphere of radius 1. Even if you then multiple the result by a random number you won't end up with an even spread and they wouldn't match the bounds of your box either. Hence I wouldn't recommend doing something with them.
So the simple answer is no - there isn't a nicer way of doing it! But you could write your own little utility function to do it to make your code a little cleaner.Fri, 25 Apr 2014 17:18:24 GMTwibble82Comment by robertbu
http://answers.unity.com/comments/694714/view.html
If you wanted a spherical collection of points around some fixed position, you could do:
var randomPosition = center + Random.insideUnitSphere * maxDist;Fri, 25 Apr 2014 17:18:01 GMTrobertbuComment by robertbu
http://answers.unity.com/comments/694709/view.html
@$$anonymous$$ikeNewall - your code was my first quick thought. But if you look at his code, it generates a set of random values within an axes aligned rectangular box at an arbitrary position. Your code generates a shell of some thickness with Vector3.zero as the origin.Fri, 25 Apr 2014 17:09:10 GMTrobertbuComment by MikeNewall
http://answers.unity.com/comments/694698/view.html
Random.onUnitSphere * Random.Range(minDistance, maxDistance);
That Would give you a random position between a min and max distance.Fri, 25 Apr 2014 16:52:31 GMTMikeNewall