Issue
I’m trying to create a little lightning effect for my weapon, and I’ve made it randomly generate based on CFrame’s and Vector3’s. I know that adding/subtracting the X, Y, or Z values doesn’t always work for every direction, therefore making the “formula” different every time. I’ve tried using math.sign() to get the sign of the LookVector unit and it hasn’t really fixed the problem. I’m wondering what I could look into to fix this problem.
Mainly it only seems to be the horizontal axis to be messing up, not the vertical ones.
Images
How it should look (does in some directions):
How it looks in others:
The black squares are the points that connect each line to one another, I made their transparency 0 to see what the issue was.
Code
Here’s the part of the code that does the plotting:
local dist = (start.Position - goal.Position).Magnitude
local previous = start
for i = 2, bends do
local part = Instance.new("Part")
part.Material = "Neon"
part.Transparency = 0
part.BrickColor = BrickColor.new("Really black")
part.Size = Vector3.new(thickness, thickness, thickness)
part.Name = "Segment " .. i
part.CanCollide = false
if i ~= bends then
if direction == "horizontal" then
part.CFrame = CFrame.new(start.Position, goal.Position)
part.CFrame = part.CFrame + Vector3.new(math.random(-horizontal, horizontal) / 10, math.random(1, vertical) / 10, math.sign(part.CFrame.LookVector.Z) * (dist / bends) * i)
else
if side == "right" then
part.CFrame = CFrame.new(start.Position, goal.Position) + Vector3.new(math.random(-horizontal, horizontal) / 10, -(dist / bends) * i, -(math.random(1, vertical) / 10))
else
part.CFrame = CFrame.new(start.Position, goal.Position) + Vector3.new(math.random(-horizontal, horizontal) / 10, (dist / bends) * i, (math.random(1, vertical) / 10))
end
end
else
part.CFrame = CFrame.new(goal.Position)
end
local weld = Instance.new("Weld")
weld.Part0 = part
weld.Part1 = start
weld.Parent = part
weld.C0 = part.CFrame:inverse() * start.CFrame
part.Parent = parent
I don’t think anymore code is needed, as this snippet deals with the plotting of the points and that seems to be the only issue. If you have any knowledge on how I could fix this, it’d be much appreciated. Thank you!