How do I turn the sphere created by planes by 90 degrees

Hello, I am having a trouble to rotate the sphere created by the planes it is made of.
The sphere starts creating under the player and ends above the player, but I want it to start creating behind the player and end in front of the player.

I would love any help I can get as I am not that good with math to understand how to turn it by 90 degrees.

local function createPlaneLine(center)
	local angleStep = math.pi / numPlanes

	for i = 1, numPlanes do
		local theta = math.pi * (i / numPlanes - 0.5)

		for j = 1, numPlanes do
			local phi = 2 * math.pi * (j / numPlanes)

			local x = radius * math.cos(theta) * math.cos(phi)
			local y = radius * math.sin(theta)
			local z = radius * math.cos(theta) * math.sin(phi)

			local rotatedX = z
			local rotatedZ = -x

			local position = center.Position + Vector3.new(rotatedX, y, rotatedZ)
			local directionToPlayer = (center.Position - position).unit

			createPlane(position, directionToPlayer)
		end
		
		wait(0.1)
	end
end
2 Likes

You can change the axis by CFrame

By default this is always on the XZ axis

So you can multiply it or use vector to world space.

CFrame.fromOrientation(0,math.pi/2,0):VectorToWorldSpace(rotatedXThing)
1 Like

It still doesn’t work right, it now spawns it rotated by 90 degrees but it always spawns on the same orientation. I would love if it would always spawn behind the player, any solution for that?

The code looks like this right now, tell me if you want the complete code.

local function createPlaneLine(center)
	local angleStep = math.pi / numPlanes

	for i = 1, numPlanes do
		local theta = math.pi * (i / numPlanes - 0.5)

		for j = 1, numPlanes do
			local phi = 2 * math.pi * (j / numPlanes)

			local x = radius * math.cos(theta) * math.cos(phi)
			local y = radius * math.sin(theta)
			local z = radius * math.cos(theta) * math.sin(phi)

			local rotatedX = z
			local rotatedZ = -x

			local position = center.Position + CFrame.fromOrientation(-90,math.pi/1.5,0):VectorToWorldSpace(Vector3.new(rotatedX, y, rotatedZ))
			local directionToPlayer = (center.Position - position).unit

			createPlane(position, directionToPlayer)
		end
		
		wait(0.1)
	end
end
1 Like

Sounds like you need to use the players root part CFrame then and then offset it along its look vector. You can do this offset using:

HrpCFrame*CFrame.new(0,0,-10)

1 Like