all of the parts form a square instead of a circle. And the parts are in a random distance from the center. (If you know what I mean). Unlike mine, the first image has it so the parts arent a random distance from the center. They are all even with eachother in distance. And also they form a circle. Unlike mine. This is the current code:
How could I make it like the first image? Where the all go together to form a circle instead of a square like mine, and also stay even with eachother inside of different distances from eachother? (Keep in mind these are parts and no particles are used)
I’m not sure this is normally possible on roblox… since it’s particles, they automatically turn around to face the camera causing the effect of the 2nd image…
I know how to tween them. my issue is how it Looks. Notice how in my recreation, all of the parts are different distances from the center? I want to make it so they are all the same distance away from the center like the image I am trying to recreate. And also, in my image, all the parts form a square instead of a circle. Probably due to me doing math.Random for a vector 3.
What you may want to do is to use the equation of a sphere to find random points. From what I have searched up, the equation is (x-h)^2+(y-k)^2+(z-l)^2 = r^2. Randomly find a pair of x and y values and calculate the z value. This will be the position of one end of the rod. Next, set the size of each “rod” to have a length. Finally, do some CFrame magic (To summarise as much as possible) to orientate each part to face the centre of the sphere, with position (h,k,l) which is based on the equation of the sphere above.
Essentially, one end of the “rod” must intersect the surface of the sphere while the other end of this “rod” should be pointed to the centre of the sphere.
I would just generate a random unit vector and set the part’s position to center+distance*unit.
Example code:
local centerPos = Vector3.new(1,2,3);
local particle = game.ServerStorage.Part;
for _=1,200 do
local unit = Vector3.new(math.random()-.5,math.random()-.5,math.random()-.5).Unit; --Generates random directional unit vector
local clone = particle:Clone();
clone.CFrame = CFrame.new(centerPos+20*unit,centerPos);
clone.Parent = workspace;
end
If you want the particle to point outwards as well, you can either use the CFrame.lookAt or CFrame.fromMatrix constructor to generate a CFrame at the desired position with the correct orientation as well.
It is just the equation of a sphere which outputs the x, y and z coordinates on the surface of a sphere. You can then put it into a Vector3 to set the position of one end of the “rod”.
Keep in mind I am a newbie at scripting. I am very used to building lol. So I would say, Vector3.new((x-h)^2+(y-k)^2+(z-l)^2 = r^2) for the positioning to be equal to a sphere instead of a square?
Let’s use the most basic scenario. Your sphere will have a centre at Vector(0,0,0) with a radius of 5 units. Substituting it into the equation and you will get the equation: x^2+y^2+z^2 = 5^2.
To randomly pick an x and y value, firstly, choose an x value between -5 and 5. Once you have this x value, choose a y value between -sqrt(5^2-x^2) and sqrt(5^2-x^2).
Finally to get your x and y value, substitute it into The equation z = sqrt(5^2 - x^2 - y^2). You will thus get your x, y and z coordinates on the sphere.
For those who want to know the rational for the specific range of x and y, the main reason is so that z doesn’t become imaginary.
For the specific case mentioned above, z = sqrt(5^2 -(x^2+y^2)), to ensure that z is not imaginary, x^2+y^2<5^2.
Let’s start by choosing a random x value. Observe that the x value must be between 5 and -5, otherwise it would be imaginary regardless of the y value.
After which, by tweaking the inequality, y^2 < 5^2-x^2 which gives -sqrt(5^2-x^2) < y < sqrt(5^2-x^2). We can thus find 5^2-x^2 using the x value we had found earlier. This is then the upper and lower limit for the inequality for choosing a y value.
If you didn’t understand this, just trust me on this one.
Your solution will only provide the positive Z solutions; you should be taking into account both the positive and negative state of your supposed final answer or OP will end up with a hemisphere.