I’ve been creating a script that creates parts about a root part in the shape of the arc of a circle. Whilst this works well, I am having trouble adjusting the angle of start & angle of end about the direction of the part.
For example instead of always being the same two angles, the angles would adjust based on which way the part faced.
local h, k = focus.Position.X, focus.Position.Z
for i = 0, 190, 10 do
local x = h + 10 * math.cos(math.rad(i))
local z = k + 10 * math.sin(math.rad(i))
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = Vector3.new(x, focus.Position.Y, z)
part.Parent = workspace
part.BrickColor = BrickColor.new("Really red")
end
You can multiply the x with focus.CFrame.RightVector and z with -focus.CFrame.LookVector to change the arc position to object space (RightVector is in the direction of x-axis and negative LookVector is in direction of z-axis).
Then just add focus.Position and the arc should be rotated based on the parts rotation.
local xOffset = (10 * math.cos(math.rad(i))) * focus.CFrame.RightVector
local zOffset = (10 * math.sin(math.rad(i))) * -focus.CFrame.LookVector
local position = focus.Position + xOffset + zOffset
I’ve done something like this before, but without using math.cos, and math.sin. Here’s how, in case you are wondering:
local dir = CFrame.Angles(math.rad(currentXAngle), math.rad(currentYAngle), math.rad(currentZAngle))
part.Position = Origin.CFrame:PointToWorldSpace(dir.LookVector*radius)
What this is doing, is creating a CFrame and modifying it’s rotational property, and then we take it’s LookVector, and multiply it by the radius. Now since we want to do all of this relative to the center of the circle, we then convert it to world space relative to the “origin” of the circle.
In your case, I assume it would look like this:
local h, k = focus.Position.X, focus.Position.Z
for i = 0, 190, 10 do
local dir = CFrame.Angles(0, math.rad(i), 0)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = focus.CFrame:PointToWorldSpace(dir.LookVector*10)
part.Parent = workspace
part.BrickColor = BrickColor.new("Really red")
end