# Multiple part projectiles

Divide the rays mag by the number points you want along your ray then multiply it by your iteration in the for loop

``````for i=1, totalNumberOfPoints do
local scalar = ( ray.magnitude / totalNumberOfPoints ) * i
--# Next apply your offset to that position
--# after you apply offset, create a part halfway between that position and the last iterations position.
--# and make the size of that part be the rays magnitude divided by total number of points
--# The direction of the part should be the the distance from the last iteration and the current iteration declared as a unit vector
end
``````
1 Like

You can get the length of the ray and then divide it by the spacing you want between each zig zag to get the number of points. Then at you can use CFframe.lookvector to line it up and add a slightly randomised CFrame (Only 2 axis) to off set it to the side and up.

from there you could create rods between each of the parts you create.

1 Like

How do I get the positions if position is a magnitude?

``````local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (hitpos-start).magnitude

for i=1, 10 do
local position = ( distance / 10 ) * i
local Offset = math.random()
position = position + Vector3.new(Offset,Offset,Offset)

local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.BrickColor = BrickColor.new("Really red")
Part.Anchored = true
Part.Position = position
Part.Size = Vector3.new(1,1,1)
--# after you apply offset, create a part halfway between that position and the last iterations position.
--# and make the size of that part be the rays magnitude divided by total number of points
--# The direction of the part should be the the distance from the last iteration and the current iteration declared as a unit vector
end
``````

Position is more of a scalar. if you multiply the direction of your ray by the “position” then you get the real position in vector3 form

1 Like

Is the direction of my ray the hitpos or mousepos? I have no idea how to get the direction of a ray

the direction should be the (startpos-endpos).Unit or vise versa

1 Like

So it goes in the opposite direction, I’m not very good with magnitudes and CFrames, it also ignores my start point and just goes from the middle of the baseplate. I really appreciate your help.

``````		local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (start-hitpos).magnitude
local direction = (start-hitpos).Unit

for i=1, 10 do

local position = ( distance / 10 ) * i
local Offset = math.random(1,2)
position = direction*position + Vector3.new(Offset,Offset,Offset)

local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.BrickColor = BrickColor.new("Really red")
Part.Position = position
Part.Size = Vector3.new(1,1,1)
``````
1 Like

lol. Do (ending-start).unit instead

1 Like

aaa what I did that, oh and i out a / 2 after it lol

also. You wanna add these positions from the position you shot the ray at. I know its a lot. Or you can just use ToObjectSpace. whatever floats your boat /shrug

Wait what, add what positions. These?

``````		local distance = (start-hitpos).magnitude
local direction = (hitpos-start).Unit
``````
``````part.CFrame = CFrame.new(direction*position+offset):toOjectSpace(CFrame.new(start))
``````
1 Like

Alright so I have my projectile positions how do I got about connecting them up?

https://gyazo.com/ba71c133ab72d1397ec6b13c7d0f4295

This is where it gets a little bit tricky, but it shouldnt be to difficult so bare with me.

``````--# We can conclude in order to get the last position in the iteration we can do...
local lastScalar = (distance / 10) * (i - 1)
local lastPosition = CFrame.new(direction*lastScalar+offset):toOjectSpace(CFrame.new(start))

--# We then need to find the position which is in the middle of the last position and the current position
--# Ill leave this as an exercise to you. After you do this, we can then worry about direction, gl. ;).
``````

I kinda changed it so it has always got even spacing. If it’s the first position then theirs no last part so what happens then. If I saved the positions in a table then I could get the last pos by doing table[number-1] ??

``````		local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (start-hitpos).magnitude
local direction = (start-hitpos).Unit

local number = 0
while true do
wait(.1)
number = number + 1
local position = ( 10 ) * number
local offset = math.random(1,2)
local pos = position*direction+Vector3.new(offset,offset,offset)
print(pos)

local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.BrickColor = BrickColor.new("Really red")
Part.CFrame = CFrame.new(pos):ToObjectSpace(CFrame.new(start))
Part.Size = Vector3.new(1,1,1)

end
``````

A for loop is much better in this regard. also if your worried about thier not being a first point, dont be. This will be fixed when we actually connect the points

I’m mixed up, I think I got it but somethings are vector 3’s and others are cframe’s. read the comments

``````		local number = 0
local positions = {}
table.insert(positions,0,startcframe)
while true do
wait(.1)
number = number + 1
local position = ( 10 ) * number
local offset = math.random(1,2)
local pos = position*direction+Vector3.new(offset,offset,offset)
print(pos)

local Cframe1 = CFrame.new(pos):ToObjectSpace(CFrame.new(start))
table.insert(positions,number,Cframe1)

print(positions[number])
local lastposition = positions[number-1]

local length = (positions[number-1]-positions[number]).magnitude --it says argument 2 vector 3 expected?
local Part = Instance.new("Part", game.Workspace.SpellEffects)
Part.Anchored = true
Part.Size = Vector3.new(0.1,0.1,length)
Part.CFrame = lastposition
end
``````

Ok I got it but now I need to orientate it. https://gyazo.com/d6916f307147e6fb5d7561d4f4594ff1

``````		local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (start-hitpos).magnitude
local direction = (start-hitpos).Unit

local number = 0
local positions = {}
table.insert(positions,0,startcframe)
while true do
wait(.1)
number = number + 1
local position = ( 10 ) * number
local offset = math.random(1,2)
local pos = position*direction+Vector3.new(offset,offset,offset)
print(pos)

local Cframe1 = CFrame.new(pos):ToObjectSpace(CFrame.new(start))
table.insert(positions,number,Cframe1)

print(positions[number])
local lastposition = positions[number-1]

local length = (positions[number-1].p-positions[number].p).magnitude
local Part = Instance.new("Part", game.Workspace.SpellEffects)
Part.Anchored = true
Part.Size = Vector3.new(0.1,0.1,length)
Part.CFrame = lastposition
end
``````

I’ll let you figure out how to orientate it using what you’ve learned.

Remember that you can get direction by doing (start-end).unit
Effectively you want to get the direction between the current position and last position.

After this you can create your CFrame for your part.
Remember, that direction is a unit vector and you will need to multiply it by a scalar in order to get a non unit vector with size.
Be sure to show me the finished project

1 Like

Yeah, I did it thank you so much. You deserve more then a solution.