- Home /

# Random vector within a range, Quaternion issue...

Hi everybody, Hope someone can help me, i'm stuck with quaternion. So my problem is :

I want to spawn particles around my emitter between two angle

```
Quaternion max = Quaternion.Euler(0.0f, 0.0f, _maxAngle);
Quaternion min = Quaternion.Euler(0.0f, 0.0f, -_maxAngle);
Vector3 maxVector = max * transform.up;
Vector3 minVector = min * transform.up;
Vector3 result = Vector3.Lerp(minVector, maxVector, Random.value);
float particleSpeed = Random.Range(_particleSpeedMin, _particleSpeedMax);
Vector3 speed = result * particleSpeed;
```

So if "_maxAngle" is equal to 30 particles spawn on a cone of 60° (between -30 and 30)

But

My problem is, if "_maxAngle" is equal to 180 so particles spawn in a straight line and not all around my emitter, i noticed that "maxVector" and "minVector" as the same value : (0,-1,0), but i don't know how to manage the problem

Thanks for your attention and hope i can read you soon

**Answer** by JonPQ
·
Jan 31 at 08:52 PM

look at your first two lines of code.... you are using _maxAngle twice.... one should be _minAngle

you will also want to Normalize result after the lerp. otherwise the vector length will be short sometimes... making slow speed

I use _maxAngle twice but for in "max" it's +_maxAngle and in min it's -_maxAngle And for the speed :

float particleSpeed = Random.Range(_particleSpeedMin, _particleSpeedMax); Vector3 speed = result * particleSpeed;

So the speed is not a problem at all

ahh I missed that.... confusing with the - and _ try using this instead ... float angle = Mathf.LerpAngle(minAngle, maxAngle, lerp); where lerp is a random value 0-1 then convert angle into a vector as you do in line 1

**Answer** by Bunny83
·
Feb 01 at 02:21 AM

Well your main issue here is that you use Lerp between your vectors. You may want to use Slerp instead. However when you have an exact 180° angle it will still has difficulties to actually define a rotation plane and the result may not be what you think.

If you're looking for a 3d version you may want to use something like my GetPointOnUnitSphereCap.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.