Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why do my parts have odd spacing between them despite the precision of the positions?

Asked by 5 years ago

I'm attempting to create a lightning effect and I have results to some extent. The positions I use to tell the projectiles where to join are precise, yet there are still spaces in between the parts. Does anybody know why? I'm using raycasting with an added entropy vector to give the parts different angles. Here's a screenshot and a portion of my script. If there's a better way to do this entirely I would appreciate if you pointed me in the right direction. Thanks.

Image

Script portion:

local Position = Character.Wand.Tip.Position
local Magnitude = (Hit.Position - Position).Magnitude
local Quantity = math.ceil(Magnitude / 10)
for I = 1, Quantity do
local Entropy = Main:Randomize(0.75)
local Guideline = Ray.new(Position, (Hit.Position - Position).Unit * 10)
local Halfray = Ray.new(Position, (Hit.Position - Position).Unit * 5)
local _, Halfpos = game.Workspace:FindPartOnRay(Halfray, Character, false, true)
local Part, End = game.Workspace:FindPartOnRay(Guideline, Character, false, true)

local CurvePart = Instance.new("Part", workspace)
local TempMag = (Position - Halfpos).Magnitude
CurvePart.Size = Vector3.new(0.25, 0.25, TempMag)
CurvePart.CFrame = CFrame.new(Position, (Halfpos + Entropy)) * CFrame.new(0, 0, -5 / 2)
CurvePart.Anchored = true
CurvePart.CanCollide = false

local RevertPart = Instance.new("Part", workspace)
TempMag = (Halfpos - End).Magnitude
RevertPart.Size = Vector3.new(0.25, 0.25, TempMag)
RevertPart.CFrame = CFrame.new((Halfpos + Entropy), End) * CFrame.new(0, 0, -5 / 2)
RevertPart.Anchored = true
RevertPart.CanCollide = false


Position = End

end

Randomize function (In case you were wondering):

function Main:Randomize(Curve)
local X = math.random(-Curve, Curve)
local Y = math.random(-Curve, Curve)
local Z = math.random(-Curve, Curve)
return Vector3.new(X, Y, Z)
end
0
This helps a lot. Post an answer and I'll give you credit. ThatPreston 354 — 5y

Answer this question