2

I'm using raycasts as a shotgun. I randomize direction of each ray:

Vector3 direction = new Vector3 (UnityEngine.Random.Range (-splash, splash), UnityEngine.Random.Range (-splash, splash), 100);

Everything works fine, but that maximum "range" of this direction is rectangle and I want an ellipse. It's hard to explain: Raycast It's seems I should use normalization somewhere, but I don't know where.

Olivier Moindrot
  • 27,132
  • 11
  • 88
  • 89
Konrad Linkowski
  • 2,351
  • 1
  • 20
  • 33

1 Answers1

2

Coordinates of points on circle can be calculated like this x = r*cos(a), y = r*sin(a). If r is random points will be inside of circle with radius of "splash";

Vector3 direction = new Vector3( Random.Range(-splash,splash)*Mathf.Cos(Random.Range(0,2*Mathf.PI)),Random.Range(-splash,splash)*Mathf.Sin(Random.Range(0,2*Mathf.PI)),0 );
Peter G
  • 155
  • 1
  • 8