- 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, 2019 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 $$anonymous$$ it's -_maxAngle And for the speed :
float particleSpeed = Random.Range(_particleSpeed$$anonymous$$in, _particleSpeed$$anonymous$$ax); Vector3 speed = result * particleSpeed;
So the speed is not a problem at all
ahh I missed that.... confusing with the - and _ try using this ins$$anonymous$$d ... float angle = $$anonymous$$athf.LerpAngle($$anonymous$$Angle, 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, 2019 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
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Make an object come on the screen at random angles from random sides 0 Answers
Random direction between maxAngle and minAangle , Quaternion issue.... 0 Answers
Distribute terrain in zones 3 Answers
2D Rotation of a Sprite - Quaternion.FromToRotation Smooth 1 Answer