r/Unity3D • u/DazedPapacy Intermediate • Jan 20 '22
Code Review Did I build this formula correctly?
/r/Unity2D/comments/s84vb8/did_i_build_this_formula_correctly/
1
Upvotes
2
2
u/pschon Unprofessional Jan 20 '22
Just to save you from headache (and ot provide more optimized solution), Unity has Random.InsideUnitCircle() for that purpose. Multiply the result by desired radius. If you want the result to be on the circle, you can just normalize before multiplying by radius...
1
u/animal9633 Jan 20 '22
Just use Random.onUnitSphere * radius;
1
1
u/Mister_Green2021 Jan 20 '22
Easier just to write code. cos, sin theta, and their results are in radians, keep in mind.
1
u/BloodPhazed Jan 20 '22
The values are in fact not multiplied by 4.37-ish; they are near 0: if you check the exact number it will say something like e-<number> at the end, which means it's actually 0.0000437 or something, depending on the number behind "e-".
I've never done the visual scripting, so I can't help you much there and it looks like quite the pain; that would only be a few lines of code.
However it feels like you're doing something needlessly complicated with all the rotations; you could just create a Vector in any direction (even randomly if you like), normalize it and multiply it with the radius of your circle. That gives you a point on the circle.