Hi,
How to get a random vector3 position? I could not find random function in C#. So below is the code which I found online -
public double RandomNumber(int minimum, int maximum)
{
Random random = new Random();
return random.Next(maximum - minimum);
}
And here is how I am using it -
Vector3 Direction()
{
Vector3 targetPos = cameraHead.Position + cameraHead.Direction * range;
targetPos = new Vector3(targetPos.X + RandomNumber(-factor, factor), targetPos.Y + RandomNumber(-factor, factor), targetPos.Z + RandomNumber(-factor, factor));
Vector3 direction = targetPos - cameraHead.Position;
return direction.Normalized;
}
It creates a random position but just in a straight line. See the picture below.
That above Direction function is taken from one of my unity game project and it works nicely in unity. Unity has its own Random function. Any suggestion will be appreciated.